Skip to content

Commit

Permalink
Merge pull request #88 from weihsinyeh/active_window
Browse files Browse the repository at this point in the history
Use different colors for active/inactive titles
  • Loading branch information
jserv authored Jan 11, 2025
2 parents 70b8150 + 3edeaae commit 053a651
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/twin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 38 additions & 1 deletion src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down
14 changes: 10 additions & 4 deletions src/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 053a651

Please sign in to comment.