1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client_list_menu.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
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.
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.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "menuframe.h"
25 #include "client_list_combined_menu.h"
32 #define MENU_NAME "client-list-combined-menu"
34 static ObMenu *combined_menu;
37 #define ADD_DESKTOP -2
38 #define REMOVE_DESKTOP -3
40 static void self_cleanup(ObMenu *menu, gpointer data)
42 menu_clear_entries(menu);
45 static gboolean self_update(ObMenuFrame *frame, gpointer data)
47 ObMenu *menu = frame->menu;
50 guint desktop, desktop_it;
52 menu_clear_entries(menu);
54 for (desktop_it = 0; desktop_it < screen_num_desktops; desktop_it++) {
55 gboolean empty = TRUE;
56 gboolean onlyiconic = TRUE;
60 desktop = screen_desktop;
61 else if (desktop <= screen_desktop)
64 menu_add_separator(menu, SEPARATOR, screen_desktop_names[desktop]);
65 for (it = focus_order; it; it = g_list_next(it)) {
66 ObClient *c = it->data;
67 if (focus_valid_target(c, desktop,
69 FALSE, TRUE, FALSE, FALSE, FALSE))
74 gchar *title = g_strdup_printf("(%s)", c->icon_title);
75 e = menu_add_normal(menu, desktop, title, NULL, FALSE);
79 e = menu_add_normal(menu, desktop, c->title, NULL, FALSE);
82 if (config_menu_show_icons) {
83 e->data.normal.icon = client_icon(c);
84 RrImageRef(e->data.normal.icon);
85 e->data.normal.icon_alpha =
86 c->iconic ? OB_ICONIC_ALPHA : 0xff;
89 e->data.normal.data = c;
93 if (empty || onlyiconic) {
94 /* no entries or only iconified windows, so add a
95 * way to go to this desktop without uniconifying a window */
97 menu_add_separator(menu, SEPARATOR, NULL);
99 e = menu_add_normal(menu, desktop, _("Go there..."), NULL, TRUE);
100 if (desktop == screen_desktop)
101 e->data.normal.enabled = FALSE;
105 if (config_menu_manage_desktops) {
106 menu_add_separator(menu, SEPARATOR, _("Manage desktops"));
107 menu_add_normal(menu, ADD_DESKTOP, _("_Add new desktop"), NULL, TRUE);
108 menu_add_normal(menu, REMOVE_DESKTOP, _("_Remove last desktop"),
112 return TRUE; /* always show the menu */
115 static void menu_execute(ObMenuEntry *self, ObMenuFrame *f,
116 ObClient *c, guint state, gpointer data)
118 if (self->id == ADD_DESKTOP) {
119 screen_add_desktop(FALSE);
120 menu_frame_hide_all();
122 else if (self->id == REMOVE_DESKTOP) {
123 screen_remove_desktop(FALSE);
124 menu_frame_hide_all();
127 ObClient *t = self->data.normal.data;
128 if (t) { /* it's set to NULL if its destroyed */
129 gboolean here = state & ShiftMask;
131 client_activate(t, TRUE, here, TRUE, TRUE, TRUE);
132 /* if the window is omnipresent then we need to go to its
134 if (!here && t->desktop == DESKTOP_ALL)
135 screen_set_desktop(self->id, FALSE);
138 screen_set_desktop(self->id, TRUE);
142 static void client_dest(ObClient *client, gpointer data)
144 /* This concise function removes all references to a closed
145 * client in the client_list_menu, so we don't have to check
148 for (eit = combined_menu->entries; eit; eit = g_list_next(eit)) {
149 ObMenuEntry *meit = eit->data;
150 if (meit->type == OB_MENU_ENTRY_TYPE_NORMAL &&
151 meit->data.normal.data == client)
153 meit->data.normal.data = NULL;
158 void client_list_combined_menu_startup(gboolean reconfig)
161 client_add_destroy_notify(client_dest, NULL);
163 combined_menu = menu_new(MENU_NAME, _("Windows"), TRUE, NULL);
164 menu_set_update_func(combined_menu, self_update);
165 menu_set_cleanup_func(combined_menu, self_cleanup);
166 menu_set_execute_func(combined_menu, menu_execute);
169 void client_list_combined_menu_shutdown(gboolean reconfig)
172 client_remove_destroy_notify(client_dest);