1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 apps_menu.c for the Openbox window manager
4 Copyright (c) 2011 Dana Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
21 #include "menuframe.h"
23 #include "apps_menu.h"
26 #include "obt/linkbase.h"
28 #include "obt/paths.h"
32 #define MENU_NAME "apps-menu"
34 static ObMenu *apps_menu;
35 static ObtLinkBase *linkbase;
36 static gboolean dirty;
38 static void self_cleanup(ObMenu *menu, gpointer data)
40 menu_clear_entries(menu);
43 static gboolean self_update(ObMenuFrame *frame, gpointer data)
45 ObMenu *menu = frame->menu;
48 if (!dirty) return TRUE; /* nothing has changed to be updated */
51 menu_add_separator(menu, SEPARATOR, screen_desktop_names[desktop]);
53 gchar *title = g_strdup_printf("(%s)", c->icon_title);
54 e = menu_add_normal(menu, desktop, title, NULL, FALSE);
57 if (config_menu_show_icons) {
58 e->data.normal.icon = client_icon(c);
59 RrImageRef(e->data.normal.icon);
60 e->data.normal.icon_alpha =
61 c->iconic ? OB_ICONIC_ALPHA : 0xff;
64 e->data.normal.data = link;
67 return TRUE; /* always show the menu */
70 static void menu_execute(ObMenuEntry *self, ObMenuFrame *f,
71 ObClient *c, guint state, gpointer data)
74 ObClient *t = self->data.normal.data;
75 if (t) { /* it's set to NULL if its destroyed */
76 gboolean here = state & ShiftMask;
78 client_activate(t, TRUE, here, TRUE, TRUE, TRUE);
79 /* if the window is omnipresent then we need to go to its
81 if (!here && t->desktop == DESKTOP_ALL)
82 screen_set_desktop(self->id, FALSE);
87 void linkbase_update(ObtLinkBase *lb, gpointer data)
92 void apps_menu_startup(gboolean reconfig)
97 paths = obt_paths_new();
98 /* XXX allow more environments, like GNOME or KDE, to be included */
99 linkbase = obt_linkbase_new(paths, ob_locale_msg,
100 OBT_LINK_ENV_OPENBOX);
101 obt_paths_unref(paths);
104 apps_menu = menu_new(MENU_NAME, _("Applications"), TRUE, NULL);
105 menu_set_update_func(apps_menu, self_update);
106 menu_set_cleanup_func(apps_menu, self_cleanup);
107 menu_set_execute_func(apps_menu, menu_execute);
110 void apps_menu_shutdown(gboolean reconfig)
113 obt_linkbase_unref(linkbase);
117 /* freed by the hash table */