From f542a21d2d13f9776f096afb8a742b60c16fccf0 Mon Sep 17 00:00:00 2001 From: retoor Date: Fri, 9 Jan 2026 00:41:45 +0100 Subject: [PATCH] chore: update c, example files --- config/config.example | 8 ++--- include/dwn.h | 8 ++--- src/client.c | 84 +++++++++++++++++++++++++++++++++++++++++-- src/config.c | 26 +++++++------- src/decorations.c | 21 ++++------- src/layout.c | 48 ++++++++++++++++++++----- src/main.c | 2 +- src/notifications.c | 5 +-- src/panel.c | 33 +++++++++++++---- src/systray.c | 4 +-- 10 files changed, 179 insertions(+), 60 deletions(-) diff --git a/config/config.example b/config/config.example index 100eedd..3fae9fd 100644 --- a/config/config.example +++ b/config/config.example @@ -18,8 +18,8 @@ focus_mode = click decorations = true [appearance] -# Border width in pixels (default: 2) -border_width = 2 +# Border width in pixels (default: 0) +border_width = 0 # Title bar height in pixels (default: 24) title_height = 24 @@ -27,8 +27,8 @@ title_height = 24 # Panel height in pixels (default: 28) panel_height = 28 -# Gap between windows in pixels (default: 4) -gap = 4 +# Gap between windows in pixels (default: 0) +gap = 0 # Font for titles and panels (default: fixed) # Use xlsfonts to list available fonts diff --git a/include/dwn.h b/include/dwn.h index f170eb7..899f94c 100644 --- a/include/dwn.h +++ b/include/dwn.h @@ -25,10 +25,10 @@ #define MAX_NOTIFICATIONS 32 #define MAX_KEYBINDINGS 64 -#define DEFAULT_BORDER_WIDTH 2 -#define DEFAULT_TITLE_HEIGHT 24 -#define DEFAULT_PANEL_HEIGHT 28 -#define DEFAULT_GAP 4 +#define DEFAULT_BORDER_WIDTH 0 +#define DEFAULT_TITLE_HEIGHT 28 +#define DEFAULT_PANEL_HEIGHT 32 +#define DEFAULT_GAP 0 typedef enum { DWN_OK = 0, diff --git a/src/client.c b/src/client.c index 3b8ca85..703b4e0 100644 --- a/src/client.c +++ b/src/client.c @@ -472,8 +472,28 @@ void client_move(Client *client, int x, int y) int area_x, area_y, area_w, area_h; layout_get_usable_area(&area_x, &area_y, &area_w, &area_h); - if (y < area_y) { - y = area_y; + int title_height = (dwn->config && dwn->config->show_decorations) ? + config_get_title_height() : 0; + int border = client->border_width; + + /* Constrain top (title bar) */ + if (y - title_height - border < area_y) { + y = area_y + title_height + border; + } + + /* Constrain bottom */ + if (y + client->height + border > area_y + area_h) { + y = area_y + area_h - client->height - border; + } + + /* Constrain left */ + if (x - border < area_x) { + x = area_x + border; + } + + /* Constrain right */ + if (x + client->width + border > area_x + area_w) { + x = area_x + area_w - client->width - border; } client->x = x; @@ -487,7 +507,25 @@ void client_resize(Client *client, int width, int height) return; } + int area_x, area_y, area_w, area_h; + layout_get_usable_area(&area_x, &area_y, &area_w, &area_h); + client_apply_size_hints(client, &width, &height); + + int border = client->border_width; + + /* Constrain height so it doesn't go under bottom panel */ + if (client->y + height + border > area_y + area_h) { + height = area_y + area_h - client->y - border; + if (height < 50) height = 50; + } + + /* Constrain width so it doesn't go off screen right */ + if (client->x + width + border > area_x + area_w) { + width = area_x + area_w - client->x - border; + if (width < 50) width = 50; + } + client->width = width; client->height = height; client_configure(client); @@ -499,7 +537,47 @@ void client_move_resize(Client *client, int x, int y, int width, int height) return; } + int area_x, area_y, area_w, area_h; + layout_get_usable_area(&area_x, &area_y, &area_w, &area_h); + client_apply_size_hints(client, &width, &height); + + int title_h = (dwn->config && dwn->config->show_decorations) ? + config_get_title_height() : 0; + int border = client->border_width; + + /* Constrain top */ + if (y - title_h - border < area_y) { + y = area_y + title_h + border; + } + + /* Constrain bottom */ + if (y + height + border > area_y + area_h) { + /* Prefer moving up first, then resizing if still too big */ + y = area_y + area_h - height - border; + if (y - title_h - border < area_y) { + y = area_y + title_h + border; + height = area_y + area_h - y - border; + } + } + + /* Constrain left */ + if (x - border < area_x) { + x = area_x + border; + } + + /* Constrain right */ + if (x + width + border > area_x + area_w) { + x = area_x + area_w - width - border; + if (x - border < area_x) { + x = area_x + border; + width = area_x + area_w - x - border; + } + } + + if (width < 50) width = 50; + if (height < 50) height = 50; + client->x = x; client->y = y; client->width = width; @@ -990,6 +1068,8 @@ void client_show(Client *client) XMapWindow(dwn->display, client->frame); } XMapWindow(dwn->display, client->window); + + panel_raise_all(); } void client_hide(Client *client) diff --git a/src/config.c b/src/config.c index 5ccfde0..4aa5372 100644 --- a/src/config.c +++ b/src/config.c @@ -12,19 +12,19 @@ #include #include -#define DEFAULT_PANEL_BG "#1a1a2e" -#define DEFAULT_PANEL_FG "#e0e0e0" -#define DEFAULT_WS_ACTIVE "#4a90d9" -#define DEFAULT_WS_INACTIVE "#3a3a4e" -#define DEFAULT_WS_URGENT "#d94a4a" -#define DEFAULT_TITLE_FOCUSED_BG "#2d3a4a" -#define DEFAULT_TITLE_FOCUSED_FG "#ffffff" -#define DEFAULT_TITLE_UNFOCUSED_BG "#1a1a1a" -#define DEFAULT_TITLE_UNFOCUSED_FG "#808080" -#define DEFAULT_BORDER_FOCUSED "#4a90d9" -#define DEFAULT_BORDER_UNFOCUSED "#333333" -#define DEFAULT_NOTIFICATION_BG "#2a2a3e" -#define DEFAULT_NOTIFICATION_FG "#ffffff" +#define DEFAULT_PANEL_BG "#080808" +#define DEFAULT_PANEL_FG "#00ff00" +#define DEFAULT_WS_ACTIVE "#ff00ff" +#define DEFAULT_WS_INACTIVE "#222222" +#define DEFAULT_WS_URGENT "#ff0000" +#define DEFAULT_TITLE_FOCUSED_BG "#00ffff" +#define DEFAULT_TITLE_FOCUSED_FG "#000000" +#define DEFAULT_TITLE_UNFOCUSED_BG "#111111" +#define DEFAULT_TITLE_UNFOCUSED_FG "#444444" +#define DEFAULT_BORDER_FOCUSED "#00ff00" +#define DEFAULT_BORDER_UNFOCUSED "#000000" +#define DEFAULT_NOTIFICATION_BG "#111111" +#define DEFAULT_NOTIFICATION_FG "#00ffff" Config *config_create(void) diff --git a/src/decorations.c b/src/decorations.c index 95e023a..f68cffe 100644 --- a/src/decorations.c +++ b/src/decorations.c @@ -164,7 +164,7 @@ void decorations_render_buttons(Client *client, bool focused) XSetForeground(dpy, dwn->gc, bg_color); XFillRectangle(dpy, client->frame, dwn->gc, close_x, button_y, BUTTON_SIZE, BUTTON_SIZE); - XSetForeground(dpy, dwn->gc, 0xcc4444); + XSetForeground(dpy, dwn->gc, 0xff0055); // Neon Red/Pink XDrawLine(dpy, client->frame, dwn->gc, close_x + 3, button_y + 3, close_x + BUTTON_SIZE - 4, button_y + BUTTON_SIZE - 4); @@ -174,14 +174,14 @@ void decorations_render_buttons(Client *client, bool focused) XSetForeground(dpy, dwn->gc, bg_color); XFillRectangle(dpy, client->frame, dwn->gc, max_x, button_y, BUTTON_SIZE, BUTTON_SIZE); - XSetForeground(dpy, dwn->gc, 0x44cc44); + XSetForeground(dpy, dwn->gc, 0x00ff00); // Neon Green XDrawRectangle(dpy, client->frame, dwn->gc, max_x + 3, button_y + 3, BUTTON_SIZE - 7, BUTTON_SIZE - 7); XSetForeground(dpy, dwn->gc, bg_color); XFillRectangle(dpy, client->frame, dwn->gc, min_x, button_y, BUTTON_SIZE, BUTTON_SIZE); - XSetForeground(dpy, dwn->gc, 0xcccc44); + XSetForeground(dpy, dwn->gc, 0xffff00); // Neon Yellow XDrawLine(dpy, client->frame, dwn->gc, min_x + 3, button_y + BUTTON_SIZE - 5, min_x + BUTTON_SIZE - 4, button_y + BUTTON_SIZE - 5); @@ -189,18 +189,9 @@ void decorations_render_buttons(Client *client, bool focused) void decorations_render_border(Client *client, bool focused) { - if (client == NULL || client->frame == None) { - return; - } - - if (dwn == NULL || dwn->display == NULL || dwn->config == NULL) { - return; - } - - const ColorScheme *colors = config_get_colors(); - unsigned long border_color = focused ? colors->border_focused : colors->border_unfocused; - - XSetWindowBorder(dwn->display, client->frame, border_color); + /* Borders are disabled for a smooth look */ + (void)client; + (void)focused; } diff --git a/src/layout.c b/src/layout.c index 5233cf3..0b62bb5 100644 --- a/src/layout.c +++ b/src/layout.c @@ -9,6 +9,8 @@ #include "workspace.h" #include "config.h" #include "util.h" +#include "panel.h" +#include "notifications.h" static const char *layout_names[] = { "Tiling", @@ -44,6 +46,9 @@ void layout_arrange(int workspace) layout_arrange_tiling(workspace); break; } + + panel_raise_all(); + notifications_raise_all(); } @@ -131,6 +136,8 @@ void layout_arrange_tiling(int workspace) void layout_arrange_floating(int workspace) { + int area_x, area_y, area_width, area_height; + layout_get_usable_area(&area_x, &area_y, &area_width, &area_height); for (Client *c = dwn->client_list; c != NULL; c = c->next) { if (c->workspace != (unsigned int)workspace) { @@ -140,18 +147,43 @@ void layout_arrange_floating(int workspace) continue; } - int area_x, area_y, area_width, area_height; - layout_get_usable_area(&area_x, &area_y, &area_width, &area_height); + int title_h = (dwn->config && dwn->config->show_decorations) ? + config_get_title_height() : 0; + int border = c->border_width; - if (c->x < area_x) c->x = area_x; - if (c->y < area_y) c->y = area_y; - if (c->x + c->width > area_x + area_width) { - c->x = area_x + area_width - c->width; + /* Constrain top */ + if (c->y - title_h - border < area_y) { + c->y = area_y + title_h + border; } - if (c->y + c->height > area_y + area_height) { - c->y = area_y + area_height - c->height; + + /* Constrain left */ + if (c->x - border < area_x) { + c->x = area_x + border; } + /* Constrain bottom */ + if (c->y + c->height + border > area_y + area_height) { + c->y = area_y + area_height - c->height - border; + /* If it still violates top after moving up, we must resize */ + if (c->y - title_h - border < area_y) { + c->y = area_y + title_h + border; + c->height = area_y + area_height - c->y - border; + } + } + + /* Constrain right */ + if (c->x + c->width + border > area_x + area_width) { + c->x = area_x + area_width - c->width - border; + /* If it still violates left after moving left, we must resize */ + if (c->x - border < area_x) { + c->x = area_x + border; + c->width = area_x + area_width - c->x - border; + } + } + + if (c->width < 50) c->width = 50; + if (c->height < 50) c->height = 50; + client_configure(c); } } diff --git a/src/main.c b/src/main.c index 01c8ea5..bf93b98 100644 --- a/src/main.c +++ b/src/main.c @@ -294,7 +294,7 @@ static void handle_configure_request(XConfigureRequestEvent *ev) wc.y = ev->y; wc.width = ev->width; wc.height = ev->height; - wc.border_width = ev->border_width; + wc.border_width = 0; wc.sibling = ev->above; wc.stack_mode = ev->detail; diff --git a/src/notifications.c b/src/notifications.c index 9d72a6a..56ebea0 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -501,13 +501,10 @@ uint32_t notification_show(const char *app_name, const char *summary, notif->window = XCreateWindow(dwn->display, dwn->root, 0, 0, notif->width, notif->height, - 1, + 0, CopyFromParent, InputOutput, CopyFromParent, CWOverrideRedirect | CWBackPixel | CWEventMask, &swa); - - XSetWindowBorder(dwn->display, notif->window, - dwn->config->colors.border_focused); } notif->next = notification_list; diff --git a/src/panel.c b/src/panel.c index 281ca7e..accb878 100644 --- a/src/panel.c +++ b/src/panel.c @@ -21,10 +21,10 @@ #include #include -#define PANEL_PADDING 8 -#define WIDGET_SPACING 12 -#define WORKSPACE_WIDTH 28 -#define TASKBAR_ITEM_WIDTH 150 +#define PANEL_PADDING 12 +#define WIDGET_SPACING 16 +#define WORKSPACE_WIDTH 36 +#define TASKBAR_ITEM_WIDTH 180 #define CLOCK_FORMAT "%H:%M:%S" #define DATE_FORMAT "%Y-%m-%d" @@ -161,6 +161,25 @@ Panel *panel_create(PanelPosition position) XA_CARDINAL, 32, PropModeReplace, (unsigned char *)strut, 4); + long strut_partial[12] = { 0 }; + if (position == PANEL_TOP) { + strut_partial[2] = panel->height; + strut_partial[8] = 0; + strut_partial[9] = dwn->screen_width - 1; + } else { + strut_partial[3] = panel->height; + strut_partial[10] = 0; + strut_partial[11] = dwn->screen_width - 1; + } + + XChangeProperty(dwn->display, panel->window, ewmh.NET_WM_STRUT_PARTIAL, + XA_CARDINAL, 32, PropModeReplace, + (unsigned char *)strut_partial, 12); + + XChangeProperty(dwn->display, panel->window, ewmh.NET_WM_WINDOW_TYPE, + XA_ATOM, 32, PropModeReplace, + (unsigned char *)&ewmh.NET_WM_WINDOW_TYPE_DOCK, 1); + LOG_DEBUG("Created %s panel at y=%d", position == PANEL_TOP ? "top" : "bottom", panel->y); @@ -319,8 +338,8 @@ void panel_render_workspaces(Panel *panel, int x, int *width) unsigned long bg = active ? colors->workspace_active : colors->panel_bg; XSetForeground(dpy, dwn->gc, bg); XFillRectangle(dpy, panel->buffer, dwn->gc, - x + i * WORKSPACE_WIDTH, 2, - WORKSPACE_WIDTH - 2, panel->height - 4); + x + i * WORKSPACE_WIDTH, 0, + WORKSPACE_WIDTH, panel->height); char num[4]; snprintf(num, sizeof(num), "%d", i + 1); @@ -389,7 +408,7 @@ void panel_render_taskbar(Panel *panel, int x, int *width) } XSetForeground(dpy, dwn->gc, bg); XFillRectangle(dpy, panel->buffer, dwn->gc, - current_x, 2, item_width - 2, panel->height - 4); + current_x, 0, item_width, panel->height); char title[260]; if (minimized) { diff --git a/src/systray.c b/src/systray.c index d08e4c3..c5aea74 100644 --- a/src/systray.c +++ b/src/systray.c @@ -507,7 +507,7 @@ void volume_slider_show(VolumeSlider *slider) slider->window = XCreateWindow(dwn->display, dwn->root, slider->x, slider->y, slider->width, slider->height, - 1, + 0, CopyFromParent, InputOutput, CopyFromParent, CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa); @@ -688,7 +688,7 @@ void dropdown_show(DropdownMenu *menu) menu->window = XCreateWindow(dwn->display, dwn->root, menu->x, menu->y, menu->width, menu->height, - 1, + 0, CopyFromParent, InputOutput, CopyFromParent, CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);