Skip to content

Add perMonitor mode to <margins> for per-monitor gap support#47

Open
dubitabam wants to merge 2 commits into
danakj:mainfrom
dubitabam:feat_Gaps
Open

Add perMonitor mode to <margins> for per-monitor gap support#47
dubitabam wants to merge 2 commits into
danakj:mainfrom
dubitabam:feat_Gaps

Conversation

@dubitabam

@dubitabam dubitabam commented Jun 18, 2026

Copy link
Copy Markdown

Problem

The existing element applies a global strut across the entire desktop. On multi-monitor setups, left/right margins only affect the outermost screen edges, making it impossible to add consistent insets per monitor.

Solution

A new perMonitor attribute on the existing element:

<margins perMonitor="yes">
    <top>8</top>
    <left>8</left>
    <right>8</right>
    <bottom>8</bottom>
</margins>

When perMonitor="yes", margins are no longer added as global struts. Instead they are applied per monitor inside screen_area() when a specific monitor head is requested, so they naturally propagate to all consumers:

Maximize (MaximizeFull, MaximizeVert, MaximizeHorz)
Snapping (MoveResizeTo, MoveToEdge)

Not affected: fullscreen windows (screen_physical_area_monitor is used there), floating windows. Panel struts (e.g. Polybar) are respected - they and the margins stack correctly.

The default (perMonitor="no") preserves existing behaviour exactly.

Changes

  • config.h/c - gboolean config_margins_per_monitor, read from the perMonitor attribute via obt_xml_attr_bool, defaults to FALSE
  • screen.c - margins skipped as struts when perMonitor="yes"; instead applied in screen_area() inside the if (head == i) block after monitor clamping
  • client.c - MoveToEdge initial fallback edge adjusted to the margin position when perMonitor="yes"
  • data/rc.xml - sample config updated with perMonitor attribute and documentation

Testing

Tested with Xephyr (single monitor) and a dual-monitor setup with Polybar strut on the bottom.

@dubitabam dubitabam changed the title Add per-monitor gap support for maximized windows Add perMonitor mode to <margins> for per-monitor gap support Jun 18, 2026
Previously, per-monitor margins were applied inside screen_area() itself, which caused unintended side effects on all callers, including _NET_WORKAREA,
window placement, and apps that self-maximize (e.g. Guake dropdown terminal).

Move margin application to the specific call sites that need it:
- client_configure_full(): maximize path (max_horz/max_vert)
- moveresizeto.c run_func(): MoveResizeTo action
- client_find_edge_directional(): per-monitor areas for MoveToEdge

So margins only affect explicit user-initiated maximize and snap actions, while floating windows and app-managed geometry remain unaffected.
@dubitabam

Copy link
Copy Markdown
Author

Fix: Move per-monitor margin application from screen_area() to specific call sites

While testing the initial implementation, I discovered a side effect: applying margins inside screen_area() affected all callers of that function, not just maximize and snap operations. This caused problems for any app that uses screen_area() indirectly, most notably drop-down terminals like Guake that call window.maximize() via GTK to fill the screen.

Root cause: screen_area() is called from many places: _NET_WORKAREA calculation, window placement (client_manage), client_find_onscreen, and others. By applying margins there, all of those were affected unintentionally.

Fix: Remove margins from screen_area() and apply them explicitly at the three call sites that should respect them:

  • client_configure_full(): maximize path (max_horz/max_vert)
  • moveresizeto.c run_func(): MoveResizeTo action
  • client_find_edge_directional(): per-monitor areas for MoveToEdge

Margins now only affect explicit user-initiated maximize and snap actions, while floating windows, _NET_WORKAREA, and app-managed window geometry remain completely unaffected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant