diff --git a/src/client.c b/src/client.c index b401f0f..add6030 100644 --- a/src/client.c +++ b/src/client.c @@ -8,6 +8,7 @@ #include #include "atoms-extern.h" +#include "base.h" #include "monitor.h" #include "types.h" #include "utils.h" @@ -64,6 +65,7 @@ static void client_add_to_tag(client_t *client, tag_t *tag) { task->client = client; task->next = tag->task_list; tag->task_list = task; + task->geometry = client->geometry; } static void client_remove_from_tag(client_t *client, tag_t *tag) { @@ -110,14 +112,32 @@ static inline void client_update_names(client_t *c) { xwindow_get_text_property(c->window, _NET_WM_ICON_NAME, &c->net_icon_name); } +static inline void client_init_geometry(client_t *c) { + area_t workarea = c->monitor->workarea; + if (c->geometry.x + client_width(c) > workarea.x + workarea.width) { + c->geometry.x = workarea.x + workarea.width - client_width(c); + } + if (c->geometry.y + client_height(c) > workarea.y + workarea.height) { + c->geometry.y = workarea.y + workarea.height - client_height(c); + } + c->geometry.x = MAX(c->geometry.x, workarea.x); + c->geometry.y = MAX(c->geometry.y, workarea.y); + + client_move_to(c, c->geometry.x, c->geometry.y); + client_resize(c, c->geometry.width, c->geometry.height); + client_change_border_color(c, &wm.color_set.active_border_color); + client_change_border_width(c, wm.border_width); +} + void client_manage(xcb_window_t window, xcb_get_geometry_reply_t *geometry_reply) { client_t *c = p_new(client_t, 1); c->window = window; - - client_move_to(c, geometry_reply->x, geometry_reply->y); - client_resize(c, geometry_reply->width, geometry_reply->height); - client_change_border_width(c, geometry_reply->border_width); + c->geometry.x = geometry_reply->x; + c->geometry.y = geometry_reply->y; + c->geometry.width = geometry_reply->width; + c->geometry.height = geometry_reply->height; + c->border_width = geometry_reply->border_width; { const xcb_params_cw_t params = { @@ -161,6 +181,7 @@ void client_manage(xcb_window_t window, c->tags = c->monitor->selected_tag->mask; } + client_init_geometry(c); client_tags_apply(c); } @@ -211,12 +232,22 @@ void client_resize(client_t *client, uint16_t width, uint16_t height) { width, height); } +void client_change_border_color(client_t *client, color_t *color) { + uint16_t mask = XCB_CW_BORDER_PIXEL; + const xcb_params_cw_t params = {.border_pixel = color->argb}; + xcb_aux_change_window_attributes(wm.xcb_conn, client->window, mask, ¶ms); + client->border_color = color; + logger("== client 0x%x border color: RGBA(#%08x), ARGB(#%08x)\n", + client->window, color->rgba, color->argb); +} + void client_change_border_width(client_t *client, uint16_t border_width) { if (client->border_width == border_width) return; uint16_t mask = XCB_CONFIG_WINDOW_BORDER_WIDTH; const xcb_params_configure_window_t params = {.border_width = border_width}; xcb_aux_configure_window(wm.xcb_conn, client->window, mask, ¶ms); client->border_width = border_width; + logger("== client 0x%x border width: %u\n", client->window, border_width); } void client_update_wm_hints(client_t *client) { diff --git a/src/client.h b/src/client.h index 2039d53..7c62d99 100644 --- a/src/client.h +++ b/src/client.h @@ -51,3 +51,10 @@ void client_focus(client_t *client); void client_stack_raise(client_t *client); bool client_is_visible(client_t *client); + +static inline uint16_t client_width(client_t *c) { + return c->geometry.width + c->border_width * 2; +} +static inline uint16_t client_height(client_t *c) { + return c->geometry.height + c->border_width * 2; +} diff --git a/src/default_config.h b/src/default_config.h index fb5863f..3a52ac4 100644 --- a/src/default_config.h +++ b/src/default_config.h @@ -14,6 +14,7 @@ static const int default_dpi = 144; static const char *const tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", nullptr, }; +static const uint16_t border_width = 1; static const uint16_t bar_y_padding = 1; static const uint16_t tag_x_padding = 10; @@ -22,6 +23,8 @@ static const char *const tag_bg = "#222222"; static const char *const active_tag_bg = "#005577"; static const char *const tag_color = "#bbbbbb"; static const char *const active_tag_color = "#eeeeee"; +static const char *const border_color = "#444444"; +static const char *const active_border_color = "#005577"; static const button_t button_list[] = { {click_tag, modifier_none, button_left, select_tag_of_current_monitor, {0}}, diff --git a/src/monitor.c b/src/monitor.c index b22cbde..fc8570f 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -255,8 +255,8 @@ void monitor_arrange(monitor_t *monitor) { if (task) { client_apply_task_geometry(c, task); } else { - int16_t x = -c->geometry.width; - int16_t y = -c->geometry.height; + int16_t x = -client_width(c); + int16_t y = -client_height(c); if (x != c->geometry.x || y != c->geometry.y) { client_move_to(c, x, y); } diff --git a/src/types.h b/src/types.h index 0242ebb..a83a3ac 100644 --- a/src/types.h +++ b/src/types.h @@ -86,6 +86,8 @@ typedef struct color_set_t { color_t active_tag_bg; color_t tag_color; color_t active_tag_color; + color_t border_color; + color_t active_border_color; } color_set_t; typedef struct padding_t { diff --git a/src/utils.h b/src/utils.h index 4f8277a..f3bc569 100644 --- a/src/utils.h +++ b/src/utils.h @@ -87,3 +87,8 @@ static inline void logger(const char *format, ...) { #else #define logger(format, ...) printf(format, ##__VA_ARGS__) #endif + +#ifdef MAX +#undef MAX +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#endif diff --git a/src/wm.c b/src/wm.c index ba7dcc3..0642327 100644 --- a/src/wm.c +++ b/src/wm.c @@ -277,6 +277,7 @@ void wm_clean(void) { } static void wm_setup(void) { + wm.border_width = border_width; wm.padding.tag_x = tag_x_padding; wm.layout_list = layout_list; wm.layout_count = (uint16_t)countof(layout_list); @@ -336,6 +337,8 @@ void wm_init_color_set(void) { color_parse(active_tag_bg, &wm.color_set.active_tag_bg); color_parse(tag_color, &wm.color_set.tag_color); color_parse(active_tag_color, &wm.color_set.active_tag_color); + color_parse(border_color, &wm.color_set.border_color); + color_parse(active_border_color, &wm.color_set.active_border_color); } void wm_setup_keybindings(void) { diff --git a/src/wm.h b/src/wm.h index dcc530f..5c0b18c 100644 --- a/src/wm.h +++ b/src/wm.h @@ -8,6 +8,7 @@ typedef struct wm_t { padding_t padding; + uint16_t border_width; uint16_t bar_height; uint16_t layout_count;