Zalgorithm

What is the GDK_SCALE environmental variable used for?

For context, I’ve been using Omarchy with its default monitor configuration for a while now:

env = GDK_SCALE,2
monitor=,preferred,auto,auto

That seemed to work OK for my laptop and external monitors:

❯ hyprctl monitors
Monitor eDP-1 (ID 0):
        1920x1080@144.00200 at 0x0
        description: LG Display 0x0625
        make: LG Display
        # ...
        availableModes: 1920x1080@144.00Hz 1920x1080@60.00Hz
        # ...

Monitor HDMI-A-1 (ID 1):
        1920x1080@60.00000 at 1280x0
        description: Acer Technologies VG270 E 433705A5D3W01
        make: Acer Technologies
        # ...
        availableModes: 1920x1080@60.00Hz 1920x1080@100.00Hz 1920x1080@74.97Hz 1920x1080@60.00Hz 1920x1080@59.94Hz 1920x1080@50.00Hz 1680x1050@59.88Hz 1280x1024@75.03Hz 1280x1024@60.02Hz 1440x900@59.90Hz 1280x960@60.00Hz 1280x800@59.91Hz 1152x864@75.00Hz 1280x720@60.00Hz 1280x720@60.00Hz 1280x720@59.94Hz 1280x720@50.00Hz 1024x768@75.03Hz 1024x768@70.07Hz 1024x768@60.00Hz 832x624@74.55Hz 800x600@75.00Hz 800x600@72.19Hz 800x600@60.32Hz 800x600@56.25Hz 720x576@50.00Hz 720x480@60.00Hz 720x480@59.94Hz 640x480@75.00Hz 640x480@72.81Hz 640x480@66.67Hz 640x480@60.00Hz 640x480@59.94Hz 640x480@59.94Hz 720x400@70.08Hz
        # ...

Processing sketch windows were 2x too large

After setting up Processing on the computer I noticed that Processing sketch windows were twice as large as they should be. A sketch with it’s size set to size(1920/2, 400) filled the full width of either monitor, when it should only have filled half the width.

The issue was the env = GDK_SCALE,2 rule in hypr/monitors.conf.

Removing that rule from my monitors.conf file and restarting the computer fixed the issue. I also added specific rules for my monitors, although I’m not sure that was needed:

# hypr/monotors.conf

# Laptop display (eDP-1) - 15.6" 1080p, scaled for readability
monitor = eDP-1, 1920x1080@144, 0x0, 1.5

# External monitor (HDMI-A-1) - positioned to the right of laptop
monitor = HDMI-A-1, 1920x1080@60, 1280x0, 1.0

# Fallback for any other monitors
monitor = , preferred, auto, auto

What is GDK_SCALE?

First, what is GDK?

GDK stands for either “GIMP Drawing Kit”, or “GDK Drawing Kit”, or “GNOME Drawing Kit”. GDK is a library that handles platform specific rendering for some Linux applications. Notably, it handles rendering for GTK2 and GTK3 applications, and applications created with GTK toolkits.

The Processing IDE (PDE) is built using GTK on Linux systems. I’m not using the PDE. It’s not clear to me if GTK is involved in creating the window that appears when I run processing-java cli --sketch=some_sketch/ --run.

GDK_SCALE and the Processing sketch window on Wayland/Hyprland

Running hyprctl clients with a sketch window open:

Window 564ad390a3f0 -> parametric_hyperbola:
        mapped: 1
        hidden: 0
        at: 2499,134
        size: 400,400
        workspace: 4 (4)
        floating: 1
        pseudo: 0
        monitor: 1
        class: processing-core-PApplet
        title: parametric_hyperbola
        initialClass: processing-core-PApplet
        initialTitle: parametric_hyperbola
        pid: 12691
        xwayland: 1
        pinned: 0
        fullscreen: 0
        fullscreenClient: 0
        grouped: 0
        tags:
        swallowing: 0
        focusHistoryID: 1
        inhibitingIdle: 0
        xdgTag:
        xdgDescription:
        contentType: none

The important detail in the hyprctl clients output is xwayland: 1. It means that the sketch window is run through XWayland and not as a native Wayland client.

The rendering path is something like:

Processing (Java) → AWT/Swing → GTK → X11 protocol → XWayland → Wayland (Hyprland)

(It seems that) XWayland clients don’t understand Wayland’s per-monitor scaling. For a native Wayland app, Hyprland (the compositor) would tell the app to render at the monitor’s scaling. For XWayland apps, Hyprland (the compositor) scales the entire buffer window after rendering. This is where the GDK_SCALE environmental variable is being applied.

Setting GDK_SCALE to 2 would be appropriate if I had a high-resolution monitor.

It’s not clear to me where the scale is being applied for Processing sketch windows. It’s possible that AWT/Swing is applying the GDK_SCALE environmental variable. (AWT is the Abstract Window Toolkit. It’s a core Java library that’s used for creating GUIs.)

How Hyprland handles XWayland apps

Source: Claude.

This is leading me to think that ANT/Swing were using the GDK_SCALE environmental variable and rendering the window at 2x the appropriate size when GDK_SCALE=2.

What is GTK?

Related to all of this, what is GTK? How does GTK relate to GDK?

GTK (GIMP Toolkit) is built on top of GDK (GIMP drawing kit, and other names, see What is GDK_SCALE? ) A typical rendering flow with GTK, GDK, and X11 or Wayland:

Your Application (e.g., file manager)
    GTK (widgets: buttons, menus, etc.)
    GDK (platform abstraction: drawing, windows, events)
Backend (X11, Wayland, etc.)