ITADN

Hyprland: Workspaces dialog is empty / monitor combos empty (missing 'global' declarations in main.py)

#127OpenGlitchtit 创建于 2026-05-02
G
Glitchtitcommented
## Summary In 0.4.0, the **Workspaces** dialog on Hyprland is unusable: it opens with no rows, and even after working around that, the per-workspace combo boxes are empty so no monitor can be assigned. Two missing `global` declarations in `nwg_displays/main.py` cause both symptoms. ## Environment - nwg-displays 0.4.0 (Arch Linux package `nwg-displays 0.4.0-1`) - Hyprland (`HYPRLAND_INSTANCE_SIGNATURE` set) - Python 3.14 - Three connected outputs (DP-1, DP-2, HDMI-A-1) ## Symptoms 1. Open `nwg-displays`, click **Workspaces** → dialog shows zero rules. 2. After the first fix below, dialog shows the expected rows (`workspace=1,monitor:` … `workspace=10,monitor:`), but every combo box is empty, so no monitor can be selected/assigned. ## Root cause Two assignments rebind module-level names inside functions without declaring them `global`, so the actual module-level values are never updated. Both readers (`create_workspaces_window_hypr`, `create_workspaces_window`) read the module-level globals. ### Bug 1 — `num_ws` stays `0` `nwg_displays/main.py` line 96: ```python num_ws = 0 ``` `main()` around line 1208: ```python num_ws = args.num_ws # local; module-level num_ws stays 0 if sway: print("[Info] Number of workspaces: {}".format(num_ws)) ``` `create_workspaces_window_hypr` (line 814+) and `create_workspaces_window` (line 755+) both do `for i in range(num_ws):` against the module global, so the dialog grid contains zero rows. ### Bug 2 — `outputs` stays `{}` `nwg_displays/main.py` line 103: ```python outputs = ( {} ) ``` `create_display_buttons()` line 668+: ```python def create_display_buttons(): global display_buttons ... outputs = list_outputs() # local; module-level outputs stays {} ``` The workspace dialog code populates the combos from the module-level `outputs`: ```python # line 845+ combo = Gtk.ComboBoxText() for key in outputs: if not config["use-desc"]: combo.append(key, key) else: desc = "{}".format(outputs[key]["description"]) combo.append(desc, desc) ``` Because the global is empty, every combo is empty and no monitor can be chosen. (The display canvas itself works because it uses the local `outputs` returned by `list_outputs()` directly.) ## Fix Two one-line additions: ```diff def create_display_buttons(): - global display_buttons + global display_buttons, outputs for item in display_buttons: item.destroy() display_buttons = [] outputs = list_outputs() ``` ```diff @@ main() + global num_ws num_ws = args.num_ws if sway: print("[Info] Number of workspaces: {}".format(num_ws)) ``` I verified locally on Hyprland that with both patches applied, the Workspaces dialog shows the correct number of rules and the combo boxes list all connected outputs, and saving writes the expected `workspaces.conf`.
0 条评论