Skip to content

Screen edge margins#91

Open
rstacruz wants to merge 4 commits intomogenson:mainfrom
rstacruz:screen-margins
Open

Screen edge margins#91
rstacruz wants to merge 4 commits intomogenson:mainfrom
rstacruz:screen-margins

Conversation

@rstacruz
Copy link
Copy Markdown

@rstacruz rstacruz commented Jul 8, 2025

Great work with PaperWM.spoon! I've been a loyal user of PaperWM on my GNOME laptop and I'm so happy to have the same on MacOS as well.

Context

  • I have a big screen (27") and I don't want to use all of it. I want to give it some margins to not use the whole screen.

  • I have another ultrawide monitor that is too wide for me. I want margins on the right side of the screen.

Solution

This implements screen_edge_margins.

Caveats:

  • setting a left screen edge margin of > 0 will make windows peek out a bit more. Eg, if screen_margin = 1, and screen_edge_margins = { left = 16 }, windows will peek out a total of 17 pixels.

Notes:

  • Setting right margin is fun on an ultrawide since it makes the "center" closer to the left!

Prior art

GNOME PaperWM has this feature as "horizontal margin" (and "top margin" and "bottom margin").

imagen

@rstacruz rstacruz changed the title Screen margins (untested WIP) Screen edge margins Jul 8, 2025
Comment thread init.lua
local right_gap = getGap("right")
local top_gap = getGap("top")
local bottom_gap = getGap("bottom")
local left_gap = getGap("left") + (PaperWM.screen_edge_margins.left or 0)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like it will work when PaperWM.screen_edge_margins is a single number (eg PaperWM.screen_edge_margins = 0). Please implement a getEdgeMargin() helper function like getGap().

Copy link
Copy Markdown
Author

@rstacruz rstacruz Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

Btw, would love to hear what you think about this: I didn't implement a numeric PaperWM.screen_edge_margins here. It seemed like a feature that would nudge the user towards a less desirable outcome. Ideally left / right should be kept at 0, otherwise windows would "peek out" from the left.

(In any case, I can implement it, but it might take me a few weeks)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow. In your addition to the README you said PaperWM.screeen_edge_margins could be a single number for the same margin on all sides, or a table with separate margins for each side.

Set PaperWM.screen_edge_margins to define additional margins around the screen edges. For example:

PaperWM.screen_edge_margins = 0 -- 0px margin on all sides (default)
-- or
PaperWM.screen_edge_margins = { top = 50, right = 20, bottom = 50, left = 20 } -- Specific margins per side

Let's say a user takes the first option add adds the following to their config:

PaperWM.screen_edge_margin = 5

Then this line (local left_gap = getGap("left") + (PaperWM.screen_edge_margins.left or 0) will crash with the following exception:

lua:1: attempt to index field 'screen_edge_margins' (a number value)

You need a helper function (similar to getGap()) that will check the type of PaperWM.screen_edge_margins before trying to index it as a table.

Next, what do you mean by windows would "peak out" from the left if the left and right screen edge margins are not 0? The canvas frame is only a smaller subset of the screen frame and a window will never be tiled beyond the edge of the canvas frame. We could add defensive checks that the user values for margins are not negative, or so large that opposite margins overlap.

Finally, take your time to edit. There is no rush.

Comment thread init.lua

-- center window
focused_frame.x = screen_frame.x + (screen_frame.w // 2) -
local screen_x = screen_frame.x + self.screen_edge_margins.left
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using getCanvas() here and center the window on the canvas.

@rstacruz
Copy link
Copy Markdown
Author

Thanks for the feedback! As luck would have it, I don't have a MacBook anymore (at least not for the next few weeks) so I can't do these changes quite yet. If anyone would like to help out feel free!

Comment thread init.lua
local right_gap = getGap("right")
local top_gap = getGap("top")
local bottom_gap = getGap("bottom")
local left_gap = getGap("left") + (PaperWM.screen_edge_margins.left or 0)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow. In your addition to the README you said PaperWM.screeen_edge_margins could be a single number for the same margin on all sides, or a table with separate margins for each side.

Set PaperWM.screen_edge_margins to define additional margins around the screen edges. For example:

PaperWM.screen_edge_margins = 0 -- 0px margin on all sides (default)
-- or
PaperWM.screen_edge_margins = { top = 50, right = 20, bottom = 50, left = 20 } -- Specific margins per side

Let's say a user takes the first option add adds the following to their config:

PaperWM.screen_edge_margin = 5

Then this line (local left_gap = getGap("left") + (PaperWM.screen_edge_margins.left or 0) will crash with the following exception:

lua:1: attempt to index field 'screen_edge_margins' (a number value)

You need a helper function (similar to getGap()) that will check the type of PaperWM.screen_edge_margins before trying to index it as a table.

Next, what do you mean by windows would "peak out" from the left if the left and right screen edge margins are not 0? The canvas frame is only a smaller subset of the screen frame and a window will never be tiled beyond the edge of the canvas frame. We could add defensive checks that the user values for margins are not negative, or so large that opposite margins overlap.

Finally, take your time to edit. There is no rush.

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.

2 participants