Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions data/rc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,11 @@
<!-- You can reserve a portion of your screen where windows will not cover when
they are maximized, or when they are initially placed.
Many programs reserve space automatically, but you can use this in other
cases. -->
<margins>
cases.
Set perMonitor="yes" to apply margins per monitor instead of as global
struts. In this mode, margins act as gaps inset from each monitor edge
and affect maximized windows and MoveToEdge snapping. -->
<margins perMonitor="no">
<top>0</top>
<bottom>0</bottom>
<left>0</left>
Expand Down
12 changes: 12 additions & 0 deletions openbox/actions/moveresizeto.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,19 @@ static gboolean run_func(ObActionsData *data, gpointer options)
}

area = screen_area(c->desktop, mon, NULL);
if (config_margins_per_monitor && mon < screen_num_monitors) {
area->x += config_margins.left;
area->y += config_margins.top;
area->width -= config_margins.left + config_margins.right;
area->height -= config_margins.top + config_margins.bottom;
}
carea = screen_area(c->desktop, cmon, NULL);
if (config_margins_per_monitor) {
carea->x += config_margins.left;
carea->y += config_margins.top;
carea->width -= config_margins.left + config_margins.right;
carea->height -= config_margins.top + config_margins.bottom;
}

/* find a target size for the client/frame. */
w = o->w;
Expand Down
23 changes: 18 additions & 5 deletions openbox/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -3096,6 +3096,13 @@ void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
a = screen_area(self->desktop, i,
(self->max_horz && self->max_vert ? NULL : &desired));

if (config_margins_per_monitor) {
a->x += config_margins.left;
a->y += config_margins.top;
a->width -= config_margins.left + config_margins.right;
a->height -= config_margins.top + config_margins.bottom;
}

/* set the size and position if maximized */
if (self->max_horz) {
*x = a->x;
Expand Down Expand Up @@ -4491,27 +4498,33 @@ void client_find_edge_directional(ObClient *self, ObDirection dir,

switch (dir) {
case OB_DIRECTION_NORTH:
edge = RECT_TOP(*a) - 1;
edge = RECT_TOP(*a) - 1 + (config_margins_per_monitor ? config_margins.top : 0);
break;
case OB_DIRECTION_SOUTH:
edge = RECT_BOTTOM(*a) + 1;
edge = RECT_BOTTOM(*a) + 1 - (config_margins_per_monitor ? config_margins.bottom : 0);
break;
case OB_DIRECTION_EAST:
edge = RECT_RIGHT(*a) + 1;
edge = RECT_RIGHT(*a) + 1 - (config_margins_per_monitor ? config_margins.right : 0);
break;
case OB_DIRECTION_WEST:
edge = RECT_LEFT(*a) - 1;
edge = RECT_LEFT(*a) - 1 + (config_margins_per_monitor ? config_margins.left : 0);
break;
default:
g_assert_not_reached();
}
/* default to the far edge, then narrow it down */
/* default to the far edge (per-monitor margin adjusted), then narrow it down */
*dest = edge;
*near_edge = TRUE;

/* search for edges of monitors */
for (i = 0; i < screen_num_monitors; ++i) {
Rect *area = screen_area(self->desktop, i, NULL);
if (config_margins_per_monitor) {
area->x += config_margins.left;
area->y += config_margins.top;
area->width -= config_margins.left + config_margins.right;
area->height -= config_margins.top + config_margins.bottom;
}
detect_edge(*area, dir, my_head, my_size, my_edge_start,
my_edge_size, dest, near_edge);
g_slice_free(Rect, area);
Expand Down
4 changes: 4 additions & 0 deletions openbox/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ guint config_primary_monitor_index;
ObPlaceMonitor config_primary_monitor;

StrutPartial config_margins;
gboolean config_margins_per_monitor;

gchar *config_theme;
gboolean config_theme_keepborder;
Expand Down Expand Up @@ -688,6 +689,8 @@ static void parse_margins(xmlNodePtr node, gpointer d)
{
xmlNodePtr n;

obt_xml_attr_bool(node, "perMonitor", &config_margins_per_monitor);

node = node->children;

if ((n = obt_xml_find_node(node, "top")))
Expand Down Expand Up @@ -1119,6 +1122,7 @@ void config_startup(ObtXmlInst *i)
obt_xml_register(i, "placement", parse_placement, NULL);

STRUT_PARTIAL_SET(config_margins, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
config_margins_per_monitor = FALSE;

obt_xml_register(i, "margins", parse_margins, NULL);

Expand Down
2 changes: 2 additions & 0 deletions openbox/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ extern ObPlaceMonitor config_primary_monitor;

/*! User-specified margins around the edge of the screen(s) */
extern StrutPartial config_margins;
/*! When TRUE, margins are applied per-monitor instead of as global struts */
extern gboolean config_margins_per_monitor;

/*! When true windows' contents are refreshed while they are resized; otherwise
they are not updated until the resize is complete */
Expand Down
18 changes: 10 additions & 8 deletions openbox/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1482,14 +1482,16 @@ void screen_update_areas(void)
if (dock_strut.bottom)
ADD_STRUT_TO_LIST(struts_bottom, DESKTOP_ALL, &dock_strut);

if (config_margins.left)
ADD_STRUT_TO_LIST(struts_left, DESKTOP_ALL, &config_margins);
if (config_margins.top)
ADD_STRUT_TO_LIST(struts_top, DESKTOP_ALL, &config_margins);
if (config_margins.right)
ADD_STRUT_TO_LIST(struts_right, DESKTOP_ALL, &config_margins);
if (config_margins.bottom)
ADD_STRUT_TO_LIST(struts_bottom, DESKTOP_ALL, &config_margins);
if (!config_margins_per_monitor) {
if (config_margins.left)
ADD_STRUT_TO_LIST(struts_left, DESKTOP_ALL, &config_margins);
if (config_margins.top)
ADD_STRUT_TO_LIST(struts_top, DESKTOP_ALL, &config_margins);
if (config_margins.right)
ADD_STRUT_TO_LIST(struts_right, DESKTOP_ALL, &config_margins);
if (config_margins.bottom)
ADD_STRUT_TO_LIST(struts_bottom, DESKTOP_ALL, &config_margins);
}

VALIDATE_STRUTS(struts_left, left,
monitor_area[screen_num_monitors].width / 2);
Expand Down