From 3edeaae54cc3b055852204c18706c9db6f2c2144 Mon Sep 17 00:00:00 2001 From: Wei-Hsin Yeh Date: Thu, 9 Jan 2025 23:53:00 +0800 Subject: [PATCH] Use different colors for active/inactive titles Implement the twin_active_pixmap() function to find the currently active pixel map and the previously active pixel map. Utilize the window's active variable to draw different frame colors for the active window and inactive windows. Close sysprog21#86 Signed-off-by: Wei-Hsin Yeh --- include/twin.h | 1 + src/screen.c | 39 ++++++++++++++++++++++++++++++++++++++- src/window.c | 14 ++++++++++---- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/include/twin.h b/include/twin.h index e2622f4..b9b9527 100644 --- a/include/twin.h +++ b/include/twin.h @@ -425,6 +425,7 @@ struct _twin_window { twin_window_style_t style; twin_rect_t client; twin_rect_t damage; + bool active; bool client_grab; bool want_focus; bool draw_queued; diff --git a/src/screen.c b/src/screen.c index 76bcfe2..c3dfb2d 100644 --- a/src/screen.c +++ b/src/screen.c @@ -151,6 +151,25 @@ static void twin_screen_span_pixmap(twin_screen_t maybe_unused *screen, op32(dst, src, p_right - p_left); } +static twin_pixmap_t *twin_active_pixmap(twin_screen_t *screen, + twin_pixmap_t **active_pix) +{ + twin_pixmap_t *p = NULL, *prev_active_pix = NULL; + /* + * Identify the previously active pixel map and the currently active pixel + * map, which is on the topmost layer. + */ + for (p = screen->bottom; p; p = p->up) { + if (p->window->active == true) { + prev_active_pix = p; + prev_active_pix->window->active = false; + } + (*active_pix) = p; + } + (*active_pix)->window->active = true; + return prev_active_pix; +} + void twin_screen_update(twin_screen_t *screen) { twin_coord_t left = screen->damage.left; @@ -170,7 +189,7 @@ void twin_screen_update(twin_screen_t *screen) if (!screen->disable && left < right && top < bottom) { twin_argb32_t *span; - twin_pixmap_t *p; + twin_pixmap_t *p, *active_pix = NULL, *prev_active_pix = NULL; twin_coord_t y; twin_coord_t width = right - left; @@ -183,6 +202,24 @@ void twin_screen_update(twin_screen_t *screen) if (screen->put_begin) (*screen->put_begin)(left, top, right, bottom, screen->closure); + + prev_active_pix = twin_active_pixmap(screen, &active_pix); + + /* + * Mark the previously active pixel map as damaged to update its + * changes. + */ + if (prev_active_pix && active_pix != prev_active_pix) { + twin_pixmap_damage(prev_active_pix, 0, 0, prev_active_pix->width, + prev_active_pix->height); + twin_window_draw(prev_active_pix->window); + } + + /* Mark the active pixel map as damaged to update its changes. */ + twin_pixmap_damage(active_pix, 0, 0, active_pix->width, + active_pix->height); + twin_window_draw(active_pix->window); + for (y = top; y < bottom; y++) { if (screen->background) { twin_pointer_t dst; diff --git a/src/window.c b/src/window.c index 72fa65a..59696fd 100644 --- a/src/window.c +++ b/src/window.c @@ -9,9 +9,10 @@ #include "twin_private.h" #define TWIN_ACTIVE_BG 0xd03b80ae -#define TWIN_INACTIVE_BG 0xff808080 +#define TWIN_INACTIVE_BG 0xffb0b0b0 #define TWIN_FRAME_TEXT 0xffffffff #define TWIN_ACTIVE_BORDER 0xff606060 +#define TWIN_INACTIVE_BORDER 0xff909090 #define TWIN_BW 0 #define TWIN_TITLE_HEIGHT 20 #define TWIN_RESIZE_SIZE ((TWIN_TITLE_HEIGHT + 4) / 5) @@ -32,6 +33,7 @@ twin_window_t *twin_window_create(twin_screen_t *screen, return NULL; window->screen = screen; window->style = style; + window->active = false; switch (window->style) { case TwinWindowApplication: left = TWIN_BW; @@ -226,9 +228,13 @@ static void twin_window_frame(twin_window_t *window) c_left, c_top); twin_path_close(path); - twin_paint_path(pixmap, TWIN_ACTIVE_BG, path); - - twin_paint_stroke(pixmap, TWIN_ACTIVE_BORDER, path, bw_2 * 2); + if (window->active) { + twin_paint_path(pixmap, TWIN_ACTIVE_BG, path); + twin_paint_stroke(pixmap, TWIN_ACTIVE_BORDER, path, bw_2 * 2); + } else { + twin_paint_path(pixmap, TWIN_INACTIVE_BG, path); + twin_paint_stroke(pixmap, TWIN_INACTIVE_BORDER, path, bw_2 * 2); + } twin_path_empty(path);