chore: update c, example files

This commit is contained in:
retoor 2026-01-09 00:41:45 +01:00
parent 52c8a57f52
commit f542a21d2d
10 changed files with 179 additions and 60 deletions

View File

@ -18,8 +18,8 @@ focus_mode = click
decorations = true decorations = true
[appearance] [appearance]
# Border width in pixels (default: 2) # Border width in pixels (default: 0)
border_width = 2 border_width = 0
# Title bar height in pixels (default: 24) # Title bar height in pixels (default: 24)
title_height = 24 title_height = 24
@ -27,8 +27,8 @@ title_height = 24
# Panel height in pixels (default: 28) # Panel height in pixels (default: 28)
panel_height = 28 panel_height = 28
# Gap between windows in pixels (default: 4) # Gap between windows in pixels (default: 0)
gap = 4 gap = 0
# Font for titles and panels (default: fixed) # Font for titles and panels (default: fixed)
# Use xlsfonts to list available fonts # Use xlsfonts to list available fonts

View File

@ -25,10 +25,10 @@
#define MAX_NOTIFICATIONS 32 #define MAX_NOTIFICATIONS 32
#define MAX_KEYBINDINGS 64 #define MAX_KEYBINDINGS 64
#define DEFAULT_BORDER_WIDTH 2 #define DEFAULT_BORDER_WIDTH 0
#define DEFAULT_TITLE_HEIGHT 24 #define DEFAULT_TITLE_HEIGHT 28
#define DEFAULT_PANEL_HEIGHT 28 #define DEFAULT_PANEL_HEIGHT 32
#define DEFAULT_GAP 4 #define DEFAULT_GAP 0
typedef enum { typedef enum {
DWN_OK = 0, DWN_OK = 0,

View File

@ -472,8 +472,28 @@ void client_move(Client *client, int x, int y)
int area_x, area_y, area_w, area_h; int area_x, area_y, area_w, area_h;
layout_get_usable_area(&area_x, &area_y, &area_w, &area_h); layout_get_usable_area(&area_x, &area_y, &area_w, &area_h);
if (y < area_y) { int title_height = (dwn->config && dwn->config->show_decorations) ?
y = area_y; 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; client->x = x;
@ -487,7 +507,25 @@ void client_resize(Client *client, int width, int height)
return; 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); 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->width = width;
client->height = height; client->height = height;
client_configure(client); client_configure(client);
@ -499,7 +537,47 @@ void client_move_resize(Client *client, int x, int y, int width, int height)
return; 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); 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->x = x;
client->y = y; client->y = y;
client->width = width; client->width = width;
@ -990,6 +1068,8 @@ void client_show(Client *client)
XMapWindow(dwn->display, client->frame); XMapWindow(dwn->display, client->frame);
} }
XMapWindow(dwn->display, client->window); XMapWindow(dwn->display, client->window);
panel_raise_all();
} }
void client_hide(Client *client) void client_hide(Client *client)

View File

@ -12,19 +12,19 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#define DEFAULT_PANEL_BG "#1a1a2e" #define DEFAULT_PANEL_BG "#080808"
#define DEFAULT_PANEL_FG "#e0e0e0" #define DEFAULT_PANEL_FG "#00ff00"
#define DEFAULT_WS_ACTIVE "#4a90d9" #define DEFAULT_WS_ACTIVE "#ff00ff"
#define DEFAULT_WS_INACTIVE "#3a3a4e" #define DEFAULT_WS_INACTIVE "#222222"
#define DEFAULT_WS_URGENT "#d94a4a" #define DEFAULT_WS_URGENT "#ff0000"
#define DEFAULT_TITLE_FOCUSED_BG "#2d3a4a" #define DEFAULT_TITLE_FOCUSED_BG "#00ffff"
#define DEFAULT_TITLE_FOCUSED_FG "#ffffff" #define DEFAULT_TITLE_FOCUSED_FG "#000000"
#define DEFAULT_TITLE_UNFOCUSED_BG "#1a1a1a" #define DEFAULT_TITLE_UNFOCUSED_BG "#111111"
#define DEFAULT_TITLE_UNFOCUSED_FG "#808080" #define DEFAULT_TITLE_UNFOCUSED_FG "#444444"
#define DEFAULT_BORDER_FOCUSED "#4a90d9" #define DEFAULT_BORDER_FOCUSED "#00ff00"
#define DEFAULT_BORDER_UNFOCUSED "#333333" #define DEFAULT_BORDER_UNFOCUSED "#000000"
#define DEFAULT_NOTIFICATION_BG "#2a2a3e" #define DEFAULT_NOTIFICATION_BG "#111111"
#define DEFAULT_NOTIFICATION_FG "#ffffff" #define DEFAULT_NOTIFICATION_FG "#00ffff"
Config *config_create(void) Config *config_create(void)

View File

@ -164,7 +164,7 @@ void decorations_render_buttons(Client *client, bool focused)
XSetForeground(dpy, dwn->gc, bg_color); XSetForeground(dpy, dwn->gc, bg_color);
XFillRectangle(dpy, client->frame, dwn->gc, close_x, button_y, BUTTON_SIZE, BUTTON_SIZE); 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, XDrawLine(dpy, client->frame, dwn->gc,
close_x + 3, button_y + 3, close_x + 3, button_y + 3,
close_x + BUTTON_SIZE - 4, button_y + BUTTON_SIZE - 4); 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); XSetForeground(dpy, dwn->gc, bg_color);
XFillRectangle(dpy, client->frame, dwn->gc, max_x, button_y, BUTTON_SIZE, BUTTON_SIZE); 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, XDrawRectangle(dpy, client->frame, dwn->gc,
max_x + 3, button_y + 3, max_x + 3, button_y + 3,
BUTTON_SIZE - 7, BUTTON_SIZE - 7); BUTTON_SIZE - 7, BUTTON_SIZE - 7);
XSetForeground(dpy, dwn->gc, bg_color); XSetForeground(dpy, dwn->gc, bg_color);
XFillRectangle(dpy, client->frame, dwn->gc, min_x, button_y, BUTTON_SIZE, BUTTON_SIZE); 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, XDrawLine(dpy, client->frame, dwn->gc,
min_x + 3, button_y + BUTTON_SIZE - 5, min_x + 3, button_y + BUTTON_SIZE - 5,
min_x + BUTTON_SIZE - 4, 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) void decorations_render_border(Client *client, bool focused)
{ {
if (client == NULL || client->frame == None) { /* Borders are disabled for a smooth look */
return; (void)client;
} (void)focused;
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);
} }

View File

@ -9,6 +9,8 @@
#include "workspace.h" #include "workspace.h"
#include "config.h" #include "config.h"
#include "util.h" #include "util.h"
#include "panel.h"
#include "notifications.h"
static const char *layout_names[] = { static const char *layout_names[] = {
"Tiling", "Tiling",
@ -44,6 +46,9 @@ void layout_arrange(int workspace)
layout_arrange_tiling(workspace); layout_arrange_tiling(workspace);
break; break;
} }
panel_raise_all();
notifications_raise_all();
} }
@ -131,6 +136,8 @@ void layout_arrange_tiling(int workspace)
void layout_arrange_floating(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) { for (Client *c = dwn->client_list; c != NULL; c = c->next) {
if (c->workspace != (unsigned int)workspace) { if (c->workspace != (unsigned int)workspace) {
@ -140,18 +147,43 @@ void layout_arrange_floating(int workspace)
continue; continue;
} }
int area_x, area_y, area_width, area_height; int title_h = (dwn->config && dwn->config->show_decorations) ?
layout_get_usable_area(&area_x, &area_y, &area_width, &area_height); config_get_title_height() : 0;
int border = c->border_width;
if (c->x < area_x) c->x = area_x; /* Constrain top */
if (c->y < area_y) c->y = area_y; if (c->y - title_h - border < area_y) {
if (c->x + c->width > area_x + area_width) { c->y = area_y + title_h + border;
c->x = area_x + area_width - c->width;
} }
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); client_configure(c);
} }
} }

View File

@ -294,7 +294,7 @@ static void handle_configure_request(XConfigureRequestEvent *ev)
wc.y = ev->y; wc.y = ev->y;
wc.width = ev->width; wc.width = ev->width;
wc.height = ev->height; wc.height = ev->height;
wc.border_width = ev->border_width; wc.border_width = 0;
wc.sibling = ev->above; wc.sibling = ev->above;
wc.stack_mode = ev->detail; wc.stack_mode = ev->detail;

View File

@ -501,13 +501,10 @@ uint32_t notification_show(const char *app_name, const char *summary,
notif->window = XCreateWindow(dwn->display, dwn->root, notif->window = XCreateWindow(dwn->display, dwn->root,
0, 0, 0, 0,
notif->width, notif->height, notif->width, notif->height,
1, 0,
CopyFromParent, InputOutput, CopyFromParent, CopyFromParent, InputOutput, CopyFromParent,
CWOverrideRedirect | CWBackPixel | CWEventMask, CWOverrideRedirect | CWBackPixel | CWEventMask,
&swa); &swa);
XSetWindowBorder(dwn->display, notif->window,
dwn->config->colors.border_focused);
} }
notif->next = notification_list; notif->next = notification_list;

View File

@ -21,10 +21,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <X11/Xft/Xft.h> #include <X11/Xft/Xft.h>
#define PANEL_PADDING 8 #define PANEL_PADDING 12
#define WIDGET_SPACING 12 #define WIDGET_SPACING 16
#define WORKSPACE_WIDTH 28 #define WORKSPACE_WIDTH 36
#define TASKBAR_ITEM_WIDTH 150 #define TASKBAR_ITEM_WIDTH 180
#define CLOCK_FORMAT "%H:%M:%S" #define CLOCK_FORMAT "%H:%M:%S"
#define DATE_FORMAT "%Y-%m-%d" #define DATE_FORMAT "%Y-%m-%d"
@ -161,6 +161,25 @@ Panel *panel_create(PanelPosition position)
XA_CARDINAL, 32, PropModeReplace, XA_CARDINAL, 32, PropModeReplace,
(unsigned char *)strut, 4); (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", LOG_DEBUG("Created %s panel at y=%d",
position == PANEL_TOP ? "top" : "bottom", panel->y); 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; unsigned long bg = active ? colors->workspace_active : colors->panel_bg;
XSetForeground(dpy, dwn->gc, bg); XSetForeground(dpy, dwn->gc, bg);
XFillRectangle(dpy, panel->buffer, dwn->gc, XFillRectangle(dpy, panel->buffer, dwn->gc,
x + i * WORKSPACE_WIDTH, 2, x + i * WORKSPACE_WIDTH, 0,
WORKSPACE_WIDTH - 2, panel->height - 4); WORKSPACE_WIDTH, panel->height);
char num[4]; char num[4];
snprintf(num, sizeof(num), "%d", i + 1); 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); XSetForeground(dpy, dwn->gc, bg);
XFillRectangle(dpy, panel->buffer, dwn->gc, 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]; char title[260];
if (minimized) { if (minimized) {

View File

@ -507,7 +507,7 @@ void volume_slider_show(VolumeSlider *slider)
slider->window = XCreateWindow(dwn->display, dwn->root, slider->window = XCreateWindow(dwn->display, dwn->root,
slider->x, slider->y, slider->x, slider->y,
slider->width, slider->height, slider->width, slider->height,
1, 0,
CopyFromParent, InputOutput, CopyFromParent, CopyFromParent, InputOutput, CopyFromParent,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask,
&swa); &swa);
@ -688,7 +688,7 @@ void dropdown_show(DropdownMenu *menu)
menu->window = XCreateWindow(dwn->display, dwn->root, menu->window = XCreateWindow(dwn->display, dwn->root,
menu->x, menu->y, menu->x, menu->y,
menu->width, menu->height, menu->width, menu->height,
1, 0,
CopyFromParent, InputOutput, CopyFromParent, CopyFromParent, InputOutput, CopyFromParent,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask,
&swa); &swa);