]> Dogcows Code - chaz/openbox/blob - openbox/focus_cycle_popup.c
c7921fa991db3b09db6e1618fd1444e7083d6e4f
[chaz/openbox] / openbox / focus_cycle_popup.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 focus_cycle_popup.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "focus_cycle_popup.h"
21 #include "popup.h"
22 #include "client.h"
23 #include "screen.h"
24 #include "focus.h"
25 #include "openbox.h"
26 #include "config.h"
27 #include "window.h"
28 #include "event.h"
29 #include "render/render.h"
30
31 #include <X11/Xlib.h>
32 #include <glib.h>
33
34 /* Size of the icons, which can appear inside or outside of a hilite box */
35 #define ICON_SIZE config_theme_window_list_icon_size
36 /* Size of the hilite box around a window's icon */
37 #define HILITE_SIZE (ICON_SIZE + 2*HILITE_OFFSET)
38 /* Width of the outer ring around the hilite box */
39 #define HILITE_WIDTH 2
40 /* Space between the outer ring around the hilite box and the icon inside it */
41 #define HILITE_MARGIN 1
42 /* Total distance from the edge of the hilite box to the icon inside it */
43 #define HILITE_OFFSET (HILITE_WIDTH + HILITE_MARGIN)
44 /* Margin area around the outside of the dialog */
45 #define OUTSIDE_BORDER 3
46 /* Margin area around the text */
47 #define TEXT_BORDER 2
48 /* Scroll the list-mode list when the cursor gets within this many rows of the
49 top or bottom */
50 #define SCROLL_MARGIN 4
51
52 typedef struct _ObFocusCyclePopup ObFocusCyclePopup;
53 typedef struct _ObFocusCyclePopupTarget ObFocusCyclePopupTarget;
54
55 struct _ObFocusCyclePopupTarget
56 {
57 ObClient *client;
58 RrImage *icon;
59 gchar *text;
60 Window iconwin;
61 /* This is used when the popup is in list mode */
62 Window textwin;
63 };
64
65 struct _ObFocusCyclePopup
66 {
67 ObWindow obwin;
68 Window bg;
69
70 /* This is used when the popup is in icon mode */
71 Window icon_mode_text;
72
73 Window list_mode_up;
74 Window list_mode_down;
75
76 GList *targets;
77 gint n_targets;
78
79 const ObFocusCyclePopupTarget *last_target;
80
81 gint maxtextw;
82
83 /* How are the list is scrolled, in scroll mode */
84 gint scroll;
85
86 RrAppearance *a_bg;
87 RrAppearance *a_text;
88 RrAppearance *a_hilite_text;
89 RrAppearance *a_icon;
90 RrAppearance *a_arrow;
91
92 gboolean mapped;
93 ObFocusCyclePopupMode mode;
94 };
95
96 /*! This popup shows all possible windows */
97 static ObFocusCyclePopup popup;
98 /*! This popup shows a single window */
99 static ObIconPopup *single_popup;
100
101 static gchar *popup_get_name (ObClient *c);
102 static void popup_setup (ObFocusCyclePopup *p,
103 gboolean create_targets,
104 gboolean iconic_windows,
105 gboolean all_desktops,
106 gboolean dock_windows,
107 gboolean desktop_windows);
108 static void popup_render (ObFocusCyclePopup *p,
109 const ObClient *c);
110
111 static Window create_window(Window parent, guint bwidth, gulong mask,
112 XSetWindowAttributes *attr)
113 {
114 return XCreateWindow(obt_display, parent, 0, 0, 1, 1, bwidth,
115 RrDepth(ob_rr_inst), InputOutput,
116 RrVisual(ob_rr_inst), mask, attr);
117 }
118
119 void focus_cycle_popup_startup(gboolean reconfig)
120 {
121 XSetWindowAttributes attrib;
122 RrPixel32 *p;
123
124 single_popup = icon_popup_new();
125
126 popup.obwin.type = OB_WINDOW_CLASS_INTERNAL;
127 popup.a_bg = RrAppearanceCopy(ob_rr_theme->osd_hilite_bg);
128 popup.a_hilite_text = RrAppearanceCopy(ob_rr_theme->osd_hilite_label);
129 popup.a_text = RrAppearanceCopy(ob_rr_theme->a_unfocused_label);
130 popup.a_icon = RrAppearanceCopy(ob_rr_theme->a_clear);
131 popup.a_arrow = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
132
133 popup.a_hilite_text->surface.parent = popup.a_bg;
134 popup.a_text->surface.parent = popup.a_bg;
135 popup.a_icon->surface.parent = popup.a_bg;
136
137 popup.a_text->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
138 popup.a_hilite_text->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
139
140 /* 2 textures. texture[0] is the icon. texture[1] is the hilight, and
141 may or may not be used */
142 RrAppearanceAddTextures(popup.a_icon, 2);
143
144 RrAppearanceClearTextures(popup.a_icon);
145 popup.a_icon->texture[0].type = RR_TEXTURE_IMAGE;
146
147 RrAppearanceClearTextures(popup.a_arrow);
148 popup.a_arrow->texture[0].type = RR_TEXTURE_MASK;
149 popup.a_arrow->texture[0].data.mask.color =
150 ob_rr_theme->osd_color;
151
152 attrib.override_redirect = True;
153 attrib.border_pixel=RrColorPixel(ob_rr_theme->osd_border_color);
154 popup.bg = create_window(obt_root(ob_screen), ob_rr_theme->obwidth,
155 CWOverrideRedirect | CWBorderPixel, &attrib);
156
157 /* create the text window used for the icon-mode popup */
158 popup.icon_mode_text = create_window(popup.bg, 0, 0, NULL);
159
160 /* create the windows for the up and down arrows */
161 popup.list_mode_up = create_window(popup.bg, 0, 0, NULL);
162 popup.list_mode_down = create_window(popup.bg, 0, 0, NULL);
163
164 popup.targets = NULL;
165 popup.n_targets = 0;
166 popup.last_target = NULL;
167
168 /* set up the hilite texture for the icon */
169 popup.a_icon->texture[1].data.rgba.width = HILITE_SIZE;
170 popup.a_icon->texture[1].data.rgba.height = HILITE_SIZE;
171 popup.a_icon->texture[1].data.rgba.alpha = 0xff;
172 p = g_new(RrPixel32, HILITE_SIZE * HILITE_SIZE);
173 popup.a_icon->texture[1].data.rgba.data = p;
174
175 /* create the hilite under the target icon */
176 {
177 RrPixel32 color;
178 gint x, y, o;
179
180 color = ((ob_rr_theme->osd_color->r & 0xff) << RrDefaultRedOffset) +
181 ((ob_rr_theme->osd_color->g & 0xff) << RrDefaultGreenOffset) +
182 ((ob_rr_theme->osd_color->b & 0xff) << RrDefaultBlueOffset);
183
184 o = 0;
185 for (x = 0; x < HILITE_SIZE; x++)
186 for (y = 0; y < HILITE_SIZE; y++) {
187 guchar a;
188
189 if (x < HILITE_WIDTH ||
190 x >= HILITE_SIZE - HILITE_WIDTH ||
191 y < HILITE_WIDTH ||
192 y >= HILITE_SIZE - HILITE_WIDTH)
193 {
194 /* the border of the target */
195 a = 0x88;
196 } else {
197 /* the background of the target */
198 a = 0x22;
199 }
200
201 p[o++] = color + (a << RrDefaultAlphaOffset);
202 }
203 }
204
205 stacking_add(INTERNAL_AS_WINDOW(&popup));
206 window_add(&popup.bg, INTERNAL_AS_WINDOW(&popup));
207 }
208
209 void focus_cycle_popup_shutdown(gboolean reconfig)
210 {
211 icon_popup_free(single_popup);
212
213 window_remove(popup.bg);
214 stacking_remove(INTERNAL_AS_WINDOW(&popup));
215
216 while(popup.targets) {
217 ObFocusCyclePopupTarget *t = popup.targets->data;
218
219 RrImageUnref(t->icon);
220 g_free(t->text);
221 XDestroyWindow(obt_display, t->iconwin);
222 XDestroyWindow(obt_display, t->textwin);
223 g_free(t);
224
225 popup.targets = g_list_delete_link(popup.targets, popup.targets);
226 }
227
228 g_free(popup.a_icon->texture[1].data.rgba.data);
229 popup.a_icon->texture[1].data.rgba.data = NULL;
230
231 XDestroyWindow(obt_display, popup.list_mode_up);
232 XDestroyWindow(obt_display, popup.list_mode_down);
233 XDestroyWindow(obt_display, popup.icon_mode_text);
234 XDestroyWindow(obt_display, popup.bg);
235
236 RrAppearanceFree(popup.a_arrow);
237 RrAppearanceFree(popup.a_icon);
238 RrAppearanceFree(popup.a_hilite_text);
239 RrAppearanceFree(popup.a_text);
240 RrAppearanceFree(popup.a_bg);
241 }
242
243 static void popup_setup(ObFocusCyclePopup *p, gboolean create_targets,
244 gboolean iconic_windows, gboolean all_desktops,
245 gboolean dock_windows, gboolean desktop_windows)
246 {
247 gint maxwidth, n;
248 GList *it;
249
250 g_assert(p->targets == NULL);
251 g_assert(p->n_targets == 0);
252
253 /* make its width to be the width of all the possible titles */
254
255 /* build a list of all the valid focus targets and measure their strings,
256 and count them */
257 maxwidth = 0;
258 n = 0;
259 for (it = g_list_last(focus_order); it; it = g_list_previous(it)) {
260 ObClient *ft = it->data;
261
262 if (focus_valid_target(ft, TRUE,
263 iconic_windows,
264 all_desktops,
265 dock_windows,
266 desktop_windows))
267 {
268 gchar *text = popup_get_name(ft);
269
270 /* measure */
271 p->a_text->texture[0].data.text.string = text;
272 maxwidth = MAX(maxwidth, RrMinWidth(p->a_text));
273
274 if (!create_targets) {
275 g_free(text);
276 } else {
277 ObFocusCyclePopupTarget *t = g_new(ObFocusCyclePopupTarget, 1);
278
279 t->client = ft;
280 t->text = text;
281 t->icon = client_icon(t->client);
282 RrImageRef(t->icon); /* own the icon so it won't go away */
283 t->iconwin = create_window(p->bg, 0, 0, NULL);
284 t->textwin = create_window(p->bg, 0, 0, NULL);
285
286 p->targets = g_list_prepend(p->targets, t);
287 ++n;
288 }
289 }
290 }
291
292 p->n_targets = n;
293 p->maxtextw = maxwidth;
294 }
295
296 static gchar *popup_get_name(ObClient *c)
297 {
298 ObClient *p;
299 gchar *title;
300 const gchar *desk = NULL;
301 gchar *ret;
302
303 /* find our highest direct parent */
304 p = client_search_top_direct_parent(c);
305
306 if (c->desktop != DESKTOP_ALL && c->desktop != screen_desktop)
307 desk = screen_desktop_names[c->desktop];
308
309 title = c->iconic ? c->icon_title : c->title;
310
311 /* use the transient's parent's title/icon if we don't have one */
312 if (p != c && title[0] == '\0')
313 title = p->iconic ? p->icon_title : p->title;
314
315 if (desk)
316 ret = g_strdup_printf("%s [%s]", title, desk);
317 else
318 ret = g_strdup(title);
319
320 return ret;
321 }
322
323 static void popup_render(ObFocusCyclePopup *p, const ObClient *c)
324 {
325 gint ml, mt, mr, mb;
326 gint l, t, r, b;
327 gint x, y, w, h;
328 Rect *screen_area = NULL;
329 gint rgbax, rgbay, rgbaw, rgbah;
330 gint i;
331 GList *it;
332 const ObFocusCyclePopupTarget *newtarget;
333 gint icons_per_row;
334 gint icon_rows;
335 gint textw, texth;
336 gint selected_pos;
337 gint last_scroll;
338
339 /* vars for icon mode */
340 gint icon_mode_textx;
341 gint icon_mode_texty;
342 gint icons_center_x;
343
344 /* vars for list mode */
345 gint list_mode_icon_column_w = HILITE_SIZE + OUTSIDE_BORDER;
346 gint up_arrow_x, down_arrow_x;
347 gint up_arrow_y, down_arrow_y;
348 gboolean showing_arrows = FALSE;
349
350 g_assert(p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ||
351 p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST);
352
353 screen_area = screen_physical_area_active();
354
355 /* get the outside margins */
356 RrMargins(p->a_bg, &ml, &mt, &mr, &mb);
357
358 /* get our outside borders */
359 l = ml + OUTSIDE_BORDER;
360 r = mr + OUTSIDE_BORDER;
361 t = mt + OUTSIDE_BORDER;
362 b = mb + OUTSIDE_BORDER;
363
364 /* get the width from the text and keep it within limits */
365 w = l + r + p->maxtextw;
366 if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
367 /* when in list mode, there are icons down the side */
368 w += list_mode_icon_column_w;
369 w = MIN(w, MAX(screen_area->width/3, POPUP_WIDTH)); /* max width */
370 w = MAX(w, POPUP_WIDTH); /* min width */
371
372 /* get the text height */
373 texth = RrMinHeight(p->a_hilite_text);
374 if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
375 texth = MAX(MAX(texth, RrMinHeight(p->a_text)), HILITE_SIZE);
376 else
377 texth += TEXT_BORDER * 2;
378
379 if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) {
380 /* how many icons will fit in that row? make the width fit that */
381 w -= l + r;
382 icons_per_row = (w + HILITE_SIZE - 1) / HILITE_SIZE;
383 w = icons_per_row * HILITE_SIZE + l + r;
384
385 /* how many rows do we need? */
386 icon_rows = (p->n_targets-1) / icons_per_row + 1;
387 } else {
388 /* in list mode, there is one column of icons.. */
389 icons_per_row = 1;
390 /* maximum is 80% of the screen height */
391 icon_rows = MIN(p->n_targets,
392 (4*screen_area->height/5) /* 80% of the screen */
393 /
394 MAX(HILITE_SIZE, texth)); /* height of each row */
395 /* but make sure there is always one */
396 icon_rows = MAX(icon_rows, 1);
397 }
398
399 /* get the text width */
400 textw = w - l - r;
401 if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
402 /* leave space on the side for the icons */
403 textw -= list_mode_icon_column_w;
404
405 if (!p->mapped)
406 /* reset the scrolling when the dialog is first shown */
407 p->scroll = 0;
408
409 /* find the height of the dialog */
410 h = t + b + (icon_rows * MAX(HILITE_SIZE, texth));
411 if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS)
412 /* in icon mode the text sits below the icons, so make some space */
413 h += OUTSIDE_BORDER + texth;
414
415 /* find the focused target */
416 newtarget = NULL;
417 for (i = 0, it = p->targets; it; ++i, it = g_list_next(it)) {
418 const ObFocusCyclePopupTarget *target = it->data;
419 if (target->client == c) {
420 /* save the target */
421 newtarget = target;
422 break;
423 }
424 }
425 selected_pos = i;
426 g_assert(newtarget != NULL);
427
428 /* scroll the list if needed */
429 last_scroll = p->scroll;
430 if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) {
431 const gint top = p->scroll + SCROLL_MARGIN;
432 const gint bottom = p->scroll + icon_rows - SCROLL_MARGIN;
433 const gint min_scroll = 0;
434 const gint max_scroll = p->n_targets - icon_rows;
435
436 if (top - selected_pos >= 0) {
437 p->scroll -= top - selected_pos + 1;
438 p->scroll = MAX(p->scroll, min_scroll);
439 } else if (selected_pos - bottom >= 0) {
440 p->scroll += selected_pos - bottom + 1;
441 p->scroll = MIN(p->scroll, max_scroll);
442 }
443 }
444
445 /* show the scroll arrows when appropriate */
446 if (p->scroll && p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) {
447 XMapWindow(obt_display, p->list_mode_up);
448 showing_arrows = TRUE;
449 } else
450 XUnmapWindow(obt_display, p->list_mode_up);
451
452 if (p->scroll < p->n_targets - icon_rows &&
453 p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
454 {
455 XMapWindow(obt_display, p->list_mode_down);
456 showing_arrows = TRUE;
457 } else
458 XUnmapWindow(obt_display, p->list_mode_down);
459
460 /* make space for the arrows */
461 if (showing_arrows)
462 h += ob_rr_theme->up_arrow_mask->height + OUTSIDE_BORDER
463 + ob_rr_theme->down_arrow_mask->height + OUTSIDE_BORDER;
464
465 /* center the icons if there is less than one row */
466 if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS && icon_rows == 1)
467 icons_center_x = (w - p->n_targets * HILITE_SIZE) / 2;
468 else
469 icons_center_x = 0;
470
471 if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) {
472 /* get the position of the text */
473 icon_mode_textx = l;
474 icon_mode_texty = h - texth - b;
475 }
476
477 /* find the position for the popup (include the outer borders) */
478 x = screen_area->x + (screen_area->width -
479 (w + ob_rr_theme->obwidth * 2)) / 2;
480 y = screen_area->y + (screen_area->height -
481 (h + ob_rr_theme->obwidth * 2)) / 2;
482
483 /* get the dimensions of the target hilite texture */
484 rgbax = ml;
485 rgbay = mt;
486 rgbaw = w - ml - mr;
487 rgbah = h - mt - mb;
488
489 if (!p->mapped) {
490 /* position the background but don't draw it */
491 XMoveResizeWindow(obt_display, p->bg, x, y, w, h);
492
493 if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS) {
494 /* position the text */
495 XMoveResizeWindow(obt_display, p->icon_mode_text,
496 icon_mode_textx, icon_mode_texty, textw, texth);
497 XMapWindow(obt_display, popup.icon_mode_text);
498 } else {
499 XUnmapWindow(obt_display, popup.icon_mode_text);
500
501 up_arrow_x = (w - ob_rr_theme->up_arrow_mask->width) / 2;
502 up_arrow_y = t;
503
504 down_arrow_x = (w - ob_rr_theme->down_arrow_mask->width) / 2;
505 down_arrow_y = h - b - ob_rr_theme->down_arrow_mask->height;
506
507 /* position the arrows */
508 XMoveResizeWindow(obt_display, p->list_mode_up,
509 up_arrow_x, up_arrow_y,
510 ob_rr_theme->up_arrow_mask->width,
511 ob_rr_theme->up_arrow_mask->height);
512 XMoveResizeWindow(obt_display, p->list_mode_down,
513 down_arrow_x, down_arrow_y,
514 ob_rr_theme->down_arrow_mask->width,
515 ob_rr_theme->down_arrow_mask->height);
516 }
517 }
518
519 /* * * draw everything * * */
520
521 /* draw the background */
522 if (!p->mapped)
523 RrPaint(p->a_bg, p->bg, w, h);
524
525 /* draw the scroll arrows */
526 if (!p->mapped && p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST) {
527 p->a_arrow->texture[0].data.mask.mask =
528 ob_rr_theme->up_arrow_mask;
529 p->a_arrow->surface.parent = p->a_bg;
530 p->a_arrow->surface.parentx = up_arrow_x;
531 p->a_arrow->surface.parenty = up_arrow_y;
532 RrPaint(p->a_arrow, p->list_mode_up,
533 ob_rr_theme->up_arrow_mask->width,
534 ob_rr_theme->up_arrow_mask->height);
535
536 p->a_arrow->texture[0].data.mask.mask =
537 ob_rr_theme->down_arrow_mask;
538 p->a_arrow->surface.parent = p->a_bg;
539 p->a_arrow->surface.parentx = down_arrow_x;
540 p->a_arrow->surface.parenty = down_arrow_y;
541 RrPaint(p->a_arrow, p->list_mode_down,
542 ob_rr_theme->down_arrow_mask->width,
543 ob_rr_theme->down_arrow_mask->height);
544 }
545
546 /* draw the icons and text */
547 for (i = 0, it = p->targets; it; ++i, it = g_list_next(it)) {
548 const ObFocusCyclePopupTarget *target = it->data;
549
550 /* have to redraw the targetted icon and last targetted icon
551 * to update the hilite */
552 if (!p->mapped || newtarget == target || p->last_target == target ||
553 last_scroll != p->scroll)
554 {
555 /* row and column start from 0 */
556 const gint row = i / icons_per_row - p->scroll;
557 const gint col = i % icons_per_row;
558 gint iconx, icony;
559 gint list_mode_textx, list_mode_texty;
560 RrAppearance *text;
561
562 /* find the coordinates for the icon */
563 iconx = icons_center_x + l + (col * HILITE_SIZE);
564 icony = t + (showing_arrows ? ob_rr_theme->up_arrow_mask->height
565 + OUTSIDE_BORDER
566 : 0)
567 + (row * MAX(texth, HILITE_SIZE))
568 + MAX(texth - HILITE_SIZE, 0) / 2;
569
570 /* find the dimensions of the text box */
571 list_mode_textx = iconx + HILITE_SIZE + TEXT_BORDER;
572 list_mode_texty = icony;
573
574 /* position the icon */
575 XMoveResizeWindow(obt_display, target->iconwin,
576 iconx, icony, HILITE_SIZE, HILITE_SIZE);
577
578 /* position the text */
579 if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
580 XMoveResizeWindow(obt_display, target->textwin,
581 list_mode_textx, list_mode_texty,
582 textw, texth);
583
584 /* show/hide the right windows */
585 if (row >= 0 && row < icon_rows) {
586 XMapWindow(obt_display, target->iconwin);
587 if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
588 XMapWindow(obt_display, target->textwin);
589 else
590 XUnmapWindow(obt_display, target->textwin);
591 } else {
592 XUnmapWindow(obt_display, target->textwin);
593 if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST)
594 XUnmapWindow(obt_display, target->iconwin);
595 else
596 XMapWindow(obt_display, target->iconwin);
597 }
598
599 /* get the icon from the client */
600 p->a_icon->texture[0].data.image.twidth = ICON_SIZE;
601 p->a_icon->texture[0].data.image.theight = ICON_SIZE;
602 p->a_icon->texture[0].data.image.tx = HILITE_OFFSET;
603 p->a_icon->texture[0].data.image.ty = HILITE_OFFSET;
604 p->a_icon->texture[0].data.image.alpha =
605 target->client->iconic ? OB_ICONIC_ALPHA : 0xff;
606 p->a_icon->texture[0].data.image.image = target->icon;
607
608 /* Draw the hilite? */
609 p->a_icon->texture[1].type = (target == newtarget) ?
610 RR_TEXTURE_RGBA : RR_TEXTURE_NONE;
611
612 /* draw the icon */
613 p->a_icon->surface.parentx = iconx;
614 p->a_icon->surface.parenty = icony;
615 RrPaint(p->a_icon, target->iconwin, HILITE_SIZE, HILITE_SIZE);
616
617 /* draw the text */
618 if (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_LIST ||
619 target == newtarget)
620 {
621 text = (target == newtarget) ? p->a_hilite_text : p->a_text;
622 text->texture[0].data.text.string = target->text;
623 text->surface.parentx =
624 p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ?
625 icon_mode_textx : list_mode_textx;
626 text->surface.parenty =
627 p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ?
628 icon_mode_texty : list_mode_texty;
629 RrPaint(text,
630 (p->mode == OB_FOCUS_CYCLE_POPUP_MODE_ICONS ?
631 p->icon_mode_text : target->textwin),
632 textw, texth);
633 }
634 }
635 }
636
637 p->last_target = newtarget;
638
639 g_free(screen_area);
640
641 XFlush(obt_display);
642 }
643
644 void focus_cycle_popup_show(ObClient *c, gboolean iconic_windows,
645 gboolean all_desktops, gboolean dock_windows,
646 gboolean desktop_windows,
647 ObFocusCyclePopupMode mode)
648 {
649 g_assert(c != NULL);
650
651 if (mode == OB_FOCUS_CYCLE_POPUP_MODE_NONE) {
652 focus_cycle_popup_hide();
653 return;
654 }
655
656 /* do this stuff only when the dialog is first showing */
657 if (!popup.mapped) {
658 popup_setup(&popup, TRUE, iconic_windows, all_desktops,
659 dock_windows, desktop_windows);
660 /* this is fixed once the dialog is shown */
661 popup.mode = mode;
662 }
663 g_assert(popup.targets != NULL);
664
665 popup_render(&popup, c);
666
667 if (!popup.mapped) {
668 /* show the dialog */
669 XMapWindow(obt_display, popup.bg);
670 XFlush(obt_display);
671 popup.mapped = TRUE;
672 screen_hide_desktop_popup();
673 }
674 }
675
676 void focus_cycle_popup_hide(void)
677 {
678 gulong ignore_start;
679
680 ignore_start = event_start_ignore_all_enters();
681
682 XUnmapWindow(obt_display, popup.bg);
683 XFlush(obt_display);
684
685 event_end_ignore_all_enters(ignore_start);
686
687 popup.mapped = FALSE;
688
689 while(popup.targets) {
690 ObFocusCyclePopupTarget *t = popup.targets->data;
691
692 RrImageUnref(t->icon);
693 g_free(t->text);
694 XDestroyWindow(obt_display, t->iconwin);
695 XDestroyWindow(obt_display, t->textwin);
696 g_free(t);
697
698 popup.targets = g_list_delete_link(popup.targets, popup.targets);
699 }
700 popup.n_targets = 0;
701 popup.last_target = NULL;
702 }
703
704 void focus_cycle_popup_single_show(struct _ObClient *c,
705 gboolean iconic_windows,
706 gboolean all_desktops,
707 gboolean dock_windows,
708 gboolean desktop_windows)
709 {
710 gchar *text;
711
712 g_assert(c != NULL);
713
714 /* do this stuff only when the dialog is first showing */
715 if (!popup.mapped) {
716 Rect *a;
717
718 popup_setup(&popup, FALSE, iconic_windows, all_desktops,
719 dock_windows, desktop_windows);
720 g_assert(popup.targets == NULL);
721
722 /* position the popup */
723 a = screen_physical_area_active();
724 icon_popup_position(single_popup, CenterGravity,
725 a->x + a->width / 2, a->y + a->height / 2);
726 icon_popup_height(single_popup, POPUP_HEIGHT);
727 icon_popup_min_width(single_popup, POPUP_WIDTH);
728 icon_popup_max_width(single_popup, MAX(a->width/3, POPUP_WIDTH));
729 icon_popup_text_width(single_popup, popup.maxtextw);
730 g_free(a);
731 }
732
733 text = popup_get_name(c);
734 icon_popup_show(single_popup, text, client_icon(c));
735 g_free(text);
736 screen_hide_desktop_popup();
737 }
738
739 void focus_cycle_popup_single_hide(void)
740 {
741 icon_popup_hide(single_popup);
742 }
This page took 0.067704 seconds and 3 git commands to generate.