Skip to content

Commit 053a651

Browse files
authored
Merge pull request #88 from weihsinyeh/active_window
Use different colors for active/inactive titles
2 parents 70b8150 + 3edeaae commit 053a651

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

include/twin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ struct _twin_window {
425425
twin_window_style_t style;
426426
twin_rect_t client;
427427
twin_rect_t damage;
428+
bool active;
428429
bool client_grab;
429430
bool want_focus;
430431
bool draw_queued;

src/screen.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,25 @@ static void twin_screen_span_pixmap(twin_screen_t maybe_unused *screen,
151151
op32(dst, src, p_right - p_left);
152152
}
153153

154+
static twin_pixmap_t *twin_active_pixmap(twin_screen_t *screen,
155+
twin_pixmap_t **active_pix)
156+
{
157+
twin_pixmap_t *p = NULL, *prev_active_pix = NULL;
158+
/*
159+
* Identify the previously active pixel map and the currently active pixel
160+
* map, which is on the topmost layer.
161+
*/
162+
for (p = screen->bottom; p; p = p->up) {
163+
if (p->window->active == true) {
164+
prev_active_pix = p;
165+
prev_active_pix->window->active = false;
166+
}
167+
(*active_pix) = p;
168+
}
169+
(*active_pix)->window->active = true;
170+
return prev_active_pix;
171+
}
172+
154173
void twin_screen_update(twin_screen_t *screen)
155174
{
156175
twin_coord_t left = screen->damage.left;
@@ -170,7 +189,7 @@ void twin_screen_update(twin_screen_t *screen)
170189

171190
if (!screen->disable && left < right && top < bottom) {
172191
twin_argb32_t *span;
173-
twin_pixmap_t *p;
192+
twin_pixmap_t *p, *active_pix = NULL, *prev_active_pix = NULL;
174193
twin_coord_t y;
175194
twin_coord_t width = right - left;
176195

@@ -183,6 +202,24 @@ void twin_screen_update(twin_screen_t *screen)
183202

184203
if (screen->put_begin)
185204
(*screen->put_begin)(left, top, right, bottom, screen->closure);
205+
206+
prev_active_pix = twin_active_pixmap(screen, &active_pix);
207+
208+
/*
209+
* Mark the previously active pixel map as damaged to update its
210+
* changes.
211+
*/
212+
if (prev_active_pix && active_pix != prev_active_pix) {
213+
twin_pixmap_damage(prev_active_pix, 0, 0, prev_active_pix->width,
214+
prev_active_pix->height);
215+
twin_window_draw(prev_active_pix->window);
216+
}
217+
218+
/* Mark the active pixel map as damaged to update its changes. */
219+
twin_pixmap_damage(active_pix, 0, 0, active_pix->width,
220+
active_pix->height);
221+
twin_window_draw(active_pix->window);
222+
186223
for (y = top; y < bottom; y++) {
187224
if (screen->background) {
188225
twin_pointer_t dst;

src/window.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
#include "twin_private.h"
1010

1111
#define TWIN_ACTIVE_BG 0xd03b80ae
12-
#define TWIN_INACTIVE_BG 0xff808080
12+
#define TWIN_INACTIVE_BG 0xffb0b0b0
1313
#define TWIN_FRAME_TEXT 0xffffffff
1414
#define TWIN_ACTIVE_BORDER 0xff606060
15+
#define TWIN_INACTIVE_BORDER 0xff909090
1516
#define TWIN_BW 0
1617
#define TWIN_TITLE_HEIGHT 20
1718
#define TWIN_RESIZE_SIZE ((TWIN_TITLE_HEIGHT + 4) / 5)
@@ -32,6 +33,7 @@ twin_window_t *twin_window_create(twin_screen_t *screen,
3233
return NULL;
3334
window->screen = screen;
3435
window->style = style;
36+
window->active = false;
3537
switch (window->style) {
3638
case TwinWindowApplication:
3739
left = TWIN_BW;
@@ -226,9 +228,13 @@ static void twin_window_frame(twin_window_t *window)
226228
c_left, c_top);
227229
twin_path_close(path);
228230

229-
twin_paint_path(pixmap, TWIN_ACTIVE_BG, path);
230-
231-
twin_paint_stroke(pixmap, TWIN_ACTIVE_BORDER, path, bw_2 * 2);
231+
if (window->active) {
232+
twin_paint_path(pixmap, TWIN_ACTIVE_BG, path);
233+
twin_paint_stroke(pixmap, TWIN_ACTIVE_BORDER, path, bw_2 * 2);
234+
} else {
235+
twin_paint_path(pixmap, TWIN_INACTIVE_BG, path);
236+
twin_paint_stroke(pixmap, TWIN_INACTIVE_BORDER, path, bw_2 * 2);
237+
}
232238

233239
twin_path_empty(path);
234240

0 commit comments

Comments
 (0)