]> Dogcows Code - chaz/openbox/blob - openbox/client_list_combined_menu.c
set a OB_ICONIFY_ALPHA define in misc.h for the 3 places to all use
[chaz/openbox] / openbox / client_list_combined_menu.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 client_list_menu.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 "openbox.h"
21 #include "menu.h"
22 #include "menuframe.h"
23 #include "action.h"
24 #include "screen.h"
25 #include "client.h"
26 #include "focus.h"
27 #include "config.h"
28 #include "gettext.h"
29
30 #include <glib.h>
31
32 #define MENU_NAME "client-list-combined-menu"
33
34 ObMenu *combined_menu;
35
36 static gboolean self_update(ObMenuFrame *frame, gpointer data)
37 {
38 ObMenu *menu = frame->menu;
39 ObMenuEntry *e;
40 GList *it;
41 gint i;
42 guint desktop;
43
44 menu_clear_entries(menu);
45
46 for (desktop = 0; desktop < screen_num_desktops; desktop++) {
47 gboolean empty = TRUE;
48 gboolean onlyiconic = TRUE;
49
50 menu_add_separator(menu, -1, screen_desktop_names[desktop]);
51 for (it = focus_order, i = 0; it; it = g_list_next(it), ++i) {
52 ObClient *c = it->data;
53 if (client_normal(c) && (!c->skip_taskbar || c->iconic) &&
54 (c->desktop == desktop || c->desktop == DESKTOP_ALL))
55 {
56 GSList *acts = NULL;
57 ObAction* act;
58 const ObClientIcon *icon;
59
60 empty = FALSE;
61
62 act = action_from_string("Activate",
63 OB_USER_ACTION_MENU_SELECTION);
64 act->data.activate.any.c = c;
65 acts = g_slist_append(acts, act);
66 act = action_from_string("Desktop",
67 OB_USER_ACTION_MENU_SELECTION);
68 act->data.desktop.desk = desktop;
69 acts = g_slist_append(acts, act);
70
71 if (c->iconic) {
72 gchar *title = g_strdup_printf("(%s)", c->icon_title);
73 e = menu_add_normal(menu, i, title, acts, FALSE);
74 g_free(title);
75 } else {
76 onlyiconic = FALSE;
77 e = menu_add_normal(menu, i, c->title, acts, FALSE);
78 }
79
80 if (config_menu_client_list_icons
81 && (icon = client_icon(c, 32, 32))) {
82 e->data.normal.icon_width = icon->width;
83 e->data.normal.icon_height = icon->height;
84 e->data.normal.icon_data = icon->data;
85 e->data.normal.icon_alpha =
86 c->iconic ? OB_ICONIC_ALPHA : 0xff;
87 }
88 }
89 }
90
91 if (empty || onlyiconic) {
92 /* no entries or only iconified windows, so add a
93 * way to go to this desktop without uniconifying a window */
94 if (!empty)
95 menu_add_separator(menu, -1, NULL);
96
97 GSList *acts = NULL;
98 ObAction* act;
99 ObMenuEntry *e;
100
101 act = action_from_string("Desktop", OB_USER_ACTION_MENU_SELECTION);
102 act->data.desktop.desk = desktop;
103 acts = g_slist_append(acts, act);
104 e = menu_add_normal(menu, 0, _("Go there..."), acts, TRUE);
105 if (desktop == screen_desktop)
106 e->data.normal.enabled = FALSE;
107 }
108 }
109 return TRUE; /* always show the menu */
110 }
111
112 /* executes it using the client in the actions, since we set that
113 when we make the actions! */
114 static void menu_execute(ObMenuEntry *self, ObMenuFrame *f,
115 ObClient *c, guint state, gpointer data,
116 Time time)
117 {
118 ObAction *a;
119
120 if (self->data.normal.actions) {
121 a = self->data.normal.actions->data;
122 action_run(self->data.normal.actions, a->data.any.c, state, time);
123 }
124 }
125
126 static void client_dest(ObClient *client, gpointer data)
127 {
128 /* This concise function removes all references to a closed
129 * client in the client_list_menu, so we don't have to check
130 * in client.c */
131 GList *eit;
132 for (eit = combined_menu->entries; eit; eit = g_list_next(eit)) {
133 ObMenuEntry *meit = eit->data;
134 if (meit->type == OB_MENU_ENTRY_TYPE_NORMAL &&
135 meit->data.normal.actions)
136 {
137 ObAction *a = meit->data.normal.actions->data;
138 ObClient *c = a->data.any.c;
139 if (c == client)
140 a->data.any.c = NULL;
141 }
142 }
143 }
144
145 void client_list_combined_menu_startup(gboolean reconfig)
146 {
147 if (!reconfig)
148 client_add_destroy_notify(client_dest, NULL);
149
150 combined_menu = menu_new(MENU_NAME, _("Windows"), TRUE, NULL);
151 menu_set_update_func(combined_menu, self_update);
152 menu_set_execute_func(combined_menu, menu_execute);
153 }
154
155 void client_list_combined_menu_shutdown(gboolean reconfig)
156 {
157 if (!reconfig)
158 client_remove_destroy_notify(client_dest);
159 }
This page took 0.047116 seconds and 5 git commands to generate.