From 171e9b382aace9d900d4cc1939d2ab7744030706 Mon Sep 17 00:00:00 2001 From: Bastien Dejean Date: Sun, 9 Dec 2012 12:01:45 +0100 Subject: [PATCH] New message: "pad" --- README.md | 10 +++++----- bspwm.1 | 7 +++++-- messages.c | 35 +++++++++++++++++++++++++++-------- settings.c | 5 ----- settings.h | 10 +--------- tree.c | 8 ++++---- types.c | 1 + types.h | 4 ++++ 8 files changed, 47 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 05dda6c..75d328a 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,9 @@ The following messages are handled: ratio VALUE Set the splitting ratio of the focused window. + pad MONITOR_NAME [TOP_PADDING [RIGHT_PADDING [BOTTOM_PADDING [LEFT_PADDING]]]] + Set the padding of the given monitor. + focus left|right|up|down Focus the neighbor window situated in the given direction. @@ -242,11 +245,8 @@ Colors are either [X color names](http://en.wikipedia.org/wiki/X11_color_names) window_gap Value of the gap that separates windows. - top_padding - bottom_padding - left_padding - right_padding - Padding space added at the sides of the screen. + {top,right,bottom,left}_padding + Padding space added at the sides of the current monitor. wm_name The value that shall be used for the _NET_WM_NAME property of the root window. diff --git a/bspwm.1 b/bspwm.1 index b26f143..043f2d9 100644 --- a/bspwm.1 +++ b/bspwm.1 @@ -125,6 +125,9 @@ Switch to automatic mode. .BI ratio " VALUE" Set the splitting ratio of the focused window. .TP +.BI pad " MONITOR_NAME [TOP_PADDING [RIGHT_PADDING [BOTTOM_PADDING [LEFT_PADDING]]]]" +Set the padding of the given monitor. +.TP .BI focus " left|right|up|down" Focus the neighbor window situated in the given direction. .TP @@ -278,8 +281,8 @@ Width of the inner, main and outer borders. .I window_gap Value of the gap that separates windows. .TP -.I {top,bottom,left,right}_padding -Padding space added at the sides of the screen. +.I {top,right,bottom,left}_padding +Padding space added at the sides of the current monitor. .TP .I wm_name The value that shall be used for the diff --git a/messages.c b/messages.c index ade55f7..12a650a 100644 --- a/messages.c +++ b/messages.c @@ -104,6 +104,25 @@ void process_message(char *msg, char *rsp) } else if (strcmp(cmd, "toggle_locked") == 0) { if (mon->desk->focus != NULL) toggle_locked(mon->desk->focus->client); + } else if (strcmp(cmd, "pad") == 0) { + char *name = strtok(NULL, TOK_SEP); + if (name != NULL) { + monitor_t *m = find_monitor(name); + if (m != NULL) { + char args[BUFSIZ] = {0}, *s; + while ((s = strtok(NULL, TOK_SEP)) != NULL) { + strncat(args, s, REMLEN(args)); + strncat(args, TOK_SEP, REMLEN(args)); + } + if (strlen(args) > 0) { + sscanf(args, "%i %i %i %i", &m->top_padding, &m->right_padding, &m->bottom_padding, &m->left_padding); + arrange(m, m->desk); + } else { + snprintf(rsp, BUFSIZ, "%i %i %i %i\n", m->top_padding, m->right_padding, m->bottom_padding, m->left_padding); + } + } + } + return; } else if (strcmp(cmd, "ratio") == 0) { char *value = strtok(NULL, TOK_SEP); if (value != NULL && mon->desk->focus != NULL) @@ -340,13 +359,13 @@ void set_setting(char *name, char *value, char *rsp) } else if (strcmp(name, "window_gap") == 0) { sscanf(value, "%i", &window_gap); } else if (strcmp(name, "left_padding") == 0) { - sscanf(value, "%i", &left_padding); + sscanf(value, "%i", &mon->left_padding); } else if (strcmp(name, "right_padding") == 0) { - sscanf(value, "%i", &right_padding); + sscanf(value, "%i", &mon->right_padding); } else if (strcmp(name, "top_padding") == 0) { - sscanf(value, "%i", &top_padding); + sscanf(value, "%i", &mon->top_padding); } else if (strcmp(name, "bottom_padding") == 0) { - sscanf(value, "%i", &bottom_padding); + sscanf(value, "%i", &mon->bottom_padding); } else if (strcmp(name, "focused_border_color") == 0) { strncpy(focused_border_color, value, sizeof(focused_border_color)); focused_border_color_pxl = get_color(focused_border_color); @@ -441,13 +460,13 @@ void get_setting(char *name, char* rsp) else if (strcmp(name, "window_gap") == 0) snprintf(rsp, BUFSIZ, "%i", window_gap); else if (strcmp(name, "left_padding") == 0) - snprintf(rsp, BUFSIZ, "%i", left_padding); + snprintf(rsp, BUFSIZ, "%i", mon->left_padding); else if (strcmp(name, "right_padding") == 0) - snprintf(rsp, BUFSIZ, "%i", right_padding); + snprintf(rsp, BUFSIZ, "%i", mon->right_padding); else if (strcmp(name, "top_padding") == 0) - snprintf(rsp, BUFSIZ, "%i", top_padding); + snprintf(rsp, BUFSIZ, "%i", mon->top_padding); else if (strcmp(name, "bottom_padding") == 0) - snprintf(rsp, BUFSIZ, "%i", bottom_padding); + snprintf(rsp, BUFSIZ, "%i", mon->bottom_padding); else if (strcmp(name, "focused_border_color") == 0) snprintf(rsp, BUFSIZ, "%s (%06X)", focused_border_color, focused_border_color_pxl); else if (strcmp(name, "active_border_color") == 0) diff --git a/settings.c b/settings.c index 6c4d062..0bfaa9c 100644 --- a/settings.c +++ b/settings.c @@ -64,12 +64,7 @@ void load_settings(void) outer_border_width = OUTER_BORDER_WIDTH; border_width = inner_border_width + main_border_width + outer_border_width; - window_gap = WINDOW_GAP; - left_padding = LEFT_PADDING; - right_padding = RIGHT_PADDING; - top_padding = TOP_PADDING; - bottom_padding = BOTTOM_PADDING; borderless_monocle = BORDERLESS_MONOCLE; gapless_monocle = GAPLESS_MONOCLE; diff --git a/settings.h b/settings.h index fbd0df5..391659d 100644 --- a/settings.h +++ b/settings.h @@ -23,13 +23,9 @@ #define INNER_BORDER_WIDTH 3 #define MAIN_BORDER_WIDTH 1 #define OUTER_BORDER_WIDTH 3 -#define SPLIT_RATIO 0.5 #define WINDOW_GAP 6 -#define TOP_PADDING 0 -#define BOTTOM_PADDING 0 -#define LEFT_PADDING 0 -#define RIGHT_PADDING 0 +#define SPLIT_RATIO 0.5 #define BORDERLESS_MONOCLE false #define GAPLESS_MONOCLE false @@ -63,10 +59,6 @@ unsigned int outer_border_width; unsigned int border_width; int window_gap; -int top_padding; -int bottom_padding; -int left_padding; -int right_padding; bool borderless_monocle; bool gapless_monocle; diff --git a/tree.c b/tree.c index 007484d..fa03869 100644 --- a/tree.c +++ b/tree.c @@ -239,10 +239,10 @@ void arrange(monitor_t *m, desktop_t *d) xcb_rectangle_t rect = m->rectangle; int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : window_gap); - rect.x += left_padding + wg; - rect.y += top_padding + wg; - rect.width -= left_padding + right_padding + wg; - rect.height -= top_padding + bottom_padding + wg; + rect.x += m->left_padding + wg; + rect.y += m->top_padding + wg; + rect.width -= m->left_padding + m->right_padding + wg; + rect.height -= m->top_padding + m->bottom_padding + wg; if (focus_follows_mouse) get_pointer_position(&pointer_position); apply_layout(m, d, d->root, rect, rect); diff --git a/types.c b/types.c index 659c1bb..7e5df67 100644 --- a/types.c +++ b/types.c @@ -27,6 +27,7 @@ monitor_t *make_monitor(xcb_rectangle_t *rect) m->rectangle = *rect; else warn("no rectangle was given for monitor '%s'\n", m->name); + m->top_padding = m->right_padding = m->bottom_padding = m->left_padding = 0; return m; } diff --git a/types.h b/types.h index 9458b77..b50c438 100644 --- a/types.h +++ b/types.h @@ -132,6 +132,10 @@ typedef struct monitor_t monitor_t; struct monitor_t { char name[MAXLEN]; xcb_rectangle_t rectangle; + int top_padding; + int right_padding; + int bottom_padding; + int left_padding; desktop_t *desk; desktop_t *last_desk; desktop_t *desk_head; -- 2.44.0