style: remove all block comments from header files
This commit is contained in:
+7
-35
@@ -13,14 +13,11 @@
|
||||
#include <stdbool.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
|
||||
/* Button dimensions */
|
||||
#define BUTTON_SIZE 16
|
||||
#define BUTTON_PADDING 4
|
||||
|
||||
/* Resize edge size */
|
||||
#define RESIZE_EDGE 8
|
||||
|
||||
/* ========== Initialization ========== */
|
||||
|
||||
void decorations_init(void)
|
||||
{
|
||||
@@ -29,10 +26,8 @@ void decorations_init(void)
|
||||
|
||||
void decorations_cleanup(void)
|
||||
{
|
||||
/* Nothing to clean up */
|
||||
}
|
||||
|
||||
/* ========== Rendering ========== */
|
||||
|
||||
void decorations_render(Client *client, bool focused)
|
||||
{
|
||||
@@ -64,25 +59,21 @@ void decorations_render_title_bar(Client *client, bool focused)
|
||||
int title_height = config_get_title_height();
|
||||
int border = client->border_width;
|
||||
|
||||
/* Set colors based on focus */
|
||||
unsigned long bg_color = focused ? colors->title_focused_bg : colors->title_unfocused_bg;
|
||||
unsigned long fg_color = focused ? colors->title_focused_fg : colors->title_unfocused_fg;
|
||||
|
||||
/* Draw title bar background */
|
||||
XSetForeground(dpy, dwn->gc, bg_color);
|
||||
XFillRectangle(dpy, client->frame, dwn->gc,
|
||||
border, border,
|
||||
client->width, title_height);
|
||||
|
||||
/* Draw title text */
|
||||
if (client->title[0] != '\0' && dwn->xft_font != NULL) {
|
||||
int text_y = border + (title_height + dwn->xft_font->ascent) / 2;
|
||||
int text_x = border + BUTTON_PADDING;
|
||||
|
||||
/* Truncate title if too long */
|
||||
int max_width = client->width - 3 * (BUTTON_SIZE + BUTTON_PADDING) - 2 * BUTTON_PADDING;
|
||||
char display_title[256];
|
||||
strncpy(display_title, client->title, sizeof(display_title) - 4); /* Leave room for "..." */
|
||||
strncpy(display_title, client->title, sizeof(display_title) - 4);
|
||||
display_title[sizeof(display_title) - 4] = '\0';
|
||||
|
||||
XGlyphInfo extents;
|
||||
@@ -90,16 +81,14 @@ void decorations_render_title_bar(Client *client, bool focused)
|
||||
(const FcChar8 *)display_title, strlen(display_title), &extents);
|
||||
int text_width = extents.xOff;
|
||||
|
||||
/* Truncate UTF-8 aware: find valid UTF-8 boundary */
|
||||
bool title_truncated = false;
|
||||
while (text_width > max_width && strlen(display_title) > 3) {
|
||||
size_t len = strlen(display_title);
|
||||
/* Move back to find UTF-8 character boundary */
|
||||
size_t cut = len - 1;
|
||||
while (cut > 0 && (display_title[cut] & 0xC0) == 0x80) {
|
||||
cut--; /* Skip continuation bytes */
|
||||
cut--;
|
||||
}
|
||||
if (cut > 0) cut--; /* Remove one more character for ellipsis space */
|
||||
if (cut > 0) cut--;
|
||||
while (cut > 0 && (display_title[cut] & 0xC0) == 0x80) {
|
||||
cut--;
|
||||
}
|
||||
@@ -114,7 +103,6 @@ void decorations_render_title_bar(Client *client, bool focused)
|
||||
strncat(display_title, "...", sizeof(display_title) - strlen(display_title) - 1);
|
||||
}
|
||||
|
||||
/* Draw with Xft for UTF-8 support */
|
||||
XftDraw *xft_draw = XftDrawCreate(dpy, client->frame,
|
||||
DefaultVisual(dpy, dwn->screen),
|
||||
dwn->colormap);
|
||||
@@ -155,7 +143,6 @@ void decorations_render_buttons(Client *client, bool focused)
|
||||
int title_height = config_get_title_height();
|
||||
int border = client->border_width;
|
||||
|
||||
/* Button positions (right-aligned) */
|
||||
int button_y = border + (title_height - BUTTON_SIZE) / 2;
|
||||
int close_x = border + client->width - BUTTON_SIZE - BUTTON_PADDING;
|
||||
int max_x = close_x - BUTTON_SIZE - BUTTON_PADDING;
|
||||
@@ -163,10 +150,9 @@ void decorations_render_buttons(Client *client, bool focused)
|
||||
|
||||
unsigned long bg_color = focused ? colors->title_focused_bg : colors->title_unfocused_bg;
|
||||
|
||||
/* Close button (red X) */
|
||||
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); /* Red */
|
||||
XSetForeground(dpy, dwn->gc, 0xcc4444);
|
||||
XDrawLine(dpy, client->frame, dwn->gc,
|
||||
close_x + 3, button_y + 3,
|
||||
close_x + BUTTON_SIZE - 4, button_y + BUTTON_SIZE - 4);
|
||||
@@ -174,18 +160,16 @@ void decorations_render_buttons(Client *client, bool focused)
|
||||
close_x + BUTTON_SIZE - 4, button_y + 3,
|
||||
close_x + 3, button_y + BUTTON_SIZE - 4);
|
||||
|
||||
/* Maximize button (square) */
|
||||
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); /* Green */
|
||||
XSetForeground(dpy, dwn->gc, 0x44cc44);
|
||||
XDrawRectangle(dpy, client->frame, dwn->gc,
|
||||
max_x + 3, button_y + 3,
|
||||
BUTTON_SIZE - 7, BUTTON_SIZE - 7);
|
||||
|
||||
/* Minimize button (line) */
|
||||
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); /* Yellow */
|
||||
XSetForeground(dpy, dwn->gc, 0xcccc44);
|
||||
XDrawLine(dpy, client->frame, dwn->gc,
|
||||
min_x + 3, button_y + BUTTON_SIZE - 5,
|
||||
min_x + BUTTON_SIZE - 4, button_y + BUTTON_SIZE - 5);
|
||||
@@ -207,18 +191,16 @@ void decorations_render_border(Client *client, bool focused)
|
||||
XSetWindowBorder(dwn->display, client->frame, border_color);
|
||||
}
|
||||
|
||||
/* ========== Hit testing ========== */
|
||||
|
||||
ButtonType decorations_hit_test_button(Client *client, int x, int y)
|
||||
{
|
||||
if (client == NULL) {
|
||||
return BUTTON_COUNT; /* No button hit */
|
||||
return BUTTON_COUNT;
|
||||
}
|
||||
|
||||
int title_height = config_get_title_height();
|
||||
int border = client->border_width;
|
||||
|
||||
/* Check if in title bar area */
|
||||
if (y < border || y > border + title_height) {
|
||||
return BUTTON_COUNT;
|
||||
}
|
||||
@@ -228,19 +210,16 @@ ButtonType decorations_hit_test_button(Client *client, int x, int y)
|
||||
int max_x = close_x - BUTTON_SIZE - BUTTON_PADDING;
|
||||
int min_x = max_x - BUTTON_SIZE - BUTTON_PADDING;
|
||||
|
||||
/* Check close button */
|
||||
if (x >= close_x && x < close_x + BUTTON_SIZE &&
|
||||
y >= button_y && y < button_y + BUTTON_SIZE) {
|
||||
return BUTTON_CLOSE;
|
||||
}
|
||||
|
||||
/* Check maximize button */
|
||||
if (x >= max_x && x < max_x + BUTTON_SIZE &&
|
||||
y >= button_y && y < button_y + BUTTON_SIZE) {
|
||||
return BUTTON_MAXIMIZE;
|
||||
}
|
||||
|
||||
/* Check minimize button */
|
||||
if (x >= min_x && x < min_x + BUTTON_SIZE &&
|
||||
y >= button_y && y < button_y + BUTTON_SIZE) {
|
||||
return BUTTON_MINIMIZE;
|
||||
@@ -258,7 +237,6 @@ bool decorations_hit_test_title_bar(Client *client, int x, int y)
|
||||
int title_height = config_get_title_height();
|
||||
int border = client->border_width;
|
||||
|
||||
/* In title bar but not on a button */
|
||||
if (y >= border && y < border + title_height) {
|
||||
ButtonType btn = decorations_hit_test_button(client, x, y);
|
||||
return btn == BUTTON_COUNT;
|
||||
@@ -280,7 +258,6 @@ bool decorations_hit_test_resize_area(Client *client, int x, int y, int *directi
|
||||
|
||||
*direction = 0;
|
||||
|
||||
/* Check edges */
|
||||
bool left = (x < RESIZE_EDGE);
|
||||
bool right = (x > frame_width - RESIZE_EDGE);
|
||||
bool top = (y < RESIZE_EDGE);
|
||||
@@ -290,7 +267,6 @@ bool decorations_hit_test_resize_area(Client *client, int x, int y, int *directi
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Encode direction as bitmask */
|
||||
if (left) *direction |= 1;
|
||||
if (right) *direction |= 2;
|
||||
if (top) *direction |= 4;
|
||||
@@ -299,7 +275,6 @@ bool decorations_hit_test_resize_area(Client *client, int x, int y, int *directi
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ========== Button actions ========== */
|
||||
|
||||
void decorations_button_press(Client *client, ButtonType button)
|
||||
{
|
||||
@@ -328,7 +303,6 @@ void decorations_button_press(Client *client, ButtonType button)
|
||||
}
|
||||
}
|
||||
|
||||
/* ========== Text rendering ========== */
|
||||
|
||||
void decorations_draw_text(Window window, GC gc, int x, int y,
|
||||
const char *text, unsigned long color)
|
||||
@@ -337,7 +311,6 @@ void decorations_draw_text(Window window, GC gc, int x, int y,
|
||||
return;
|
||||
}
|
||||
|
||||
/* Use Xft for UTF-8 support */
|
||||
if (dwn->xft_font != NULL) {
|
||||
XftDraw *xft_draw = XftDrawCreate(dwn->display, window,
|
||||
DefaultVisual(dwn->display, dwn->screen),
|
||||
@@ -363,7 +336,6 @@ void decorations_draw_text(Window window, GC gc, int x, int y,
|
||||
}
|
||||
}
|
||||
|
||||
/* Fallback to legacy X11 text */
|
||||
XSetForeground(dwn->display, gc, color);
|
||||
XDrawString(dwn->display, window, gc, x, y, text, strlen(text));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user