WIP: Add an xdg applications menu (it doesn't have anything in it yet, but it does...
authorDana Jansens <danakj@orodu.net>
Mon, 24 Jan 2011 22:06:41 +0000 (17:06 -0500)
committerDana Jansens <danakj@orodu.net>
Sun, 16 Oct 2011 22:54:04 +0000 (18:54 -0400)
Makefile.am
openbox/apps_menu.c [new file with mode: 0644]
openbox/apps_menu.h [new file with mode: 0644]
openbox/menu.c

index e63184e08a580d53de0b51def77f479bcb4c394c..33bcdf7ceac008e9632a3c5b89fe97ea30c33602 100644 (file)
@@ -236,6 +236,8 @@ openbox_openbox_SOURCES = \
        openbox/actions/unfocus.c \
        openbox/actions.c \
        openbox/actions.h \
+       openbox/apps_menu.c \
+       openbox/apps_menu.h \
        openbox/client.c \
        openbox/client.h \
        openbox/client_list_menu.c \
diff --git a/openbox/apps_menu.c b/openbox/apps_menu.c
new file mode 100644 (file)
index 0000000..d46ba6e
--- /dev/null
@@ -0,0 +1,120 @@
+/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
+
+   apps_menu.c for the Openbox window manager
+   Copyright (c) 2011        Dana Jansens
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   See the COPYING file for a copy of the GNU General Public License.
+*/
+
+#include "openbox.h"
+#include "menu.h"
+#include "menuframe.h"
+#include "screen.h"
+#include "apps_menu.h"
+#include "config.h"
+#include "gettext.h"
+#include "obt/linkbase.h"
+#include "obt/link.h"
+#include "obt/paths.h"
+
+#include <glib.h>
+
+#define MENU_NAME "apps-menu"
+
+static ObMenu *apps_menu;
+static ObtLinkBase *linkbase;
+static gboolean dirty;
+
+static void self_destroy(ObMenu *menu, gpointer data)
+{
+    obt_linkbase_unref(linkbase);
+    linkbase = NULL;
+}
+
+static void self_cleanup(ObMenu *menu, gpointer data)
+{
+    menu_clear_entries(menu);
+}
+
+static gboolean self_update(ObMenuFrame *frame, gpointer data)
+{
+    ObMenu *menu = frame->menu;
+    ObMenuEntry *e;
+
+    if (!dirty) return TRUE;  /* nothing has changed to be updated */
+
+/*
+    menu_add_separator(menu, SEPARATOR, screen_desktop_names[desktop]);
+
+    gchar *title = g_strdup_printf("(%s)", c->icon_title);
+    e = menu_add_normal(menu, desktop, title, NULL, FALSE);
+    g_free(title);
+
+    if (config_menu_show_icons) {
+        e->data.normal.icon = client_icon(c);
+        RrImageRef(e->data.normal.icon);
+        e->data.normal.icon_alpha =
+            c->iconic ? OB_ICONIC_ALPHA : 0xff;
+    }
+
+    e->data.normal.data = link;
+*/
+
+    return TRUE; /* always show the menu */
+}
+
+static void menu_execute(ObMenuEntry *self, ObMenuFrame *f,
+                         ObClient *c, guint state, gpointer data)
+{
+#if 0
+    ObClient *t = self->data.normal.data;
+    if (t) { /* it's set to NULL if its destroyed */
+        gboolean here = state & ShiftMask;
+
+        client_activate(t, TRUE, here, TRUE, TRUE, TRUE);
+        /* if the window is omnipresent then we need to go to its
+           desktop */
+        if (!here && t->desktop == DESKTOP_ALL)
+            screen_set_desktop(self->id, FALSE);
+    }
+#endif
+}
+
+void linkbase_update(ObtLinkBase *lb, gpointer data)
+{
+    dirty = TRUE;
+}
+
+void apps_menu_startup(gboolean reconfig)
+{
+    if (!reconfig) {
+        ObtPaths *paths;
+
+        paths = obt_paths_new();
+        /* XXX allow more environments, like GNOME or KDE, to be included */
+        linkbase = obt_linkbase_new(paths, ob_locale_msg,
+                                    OBT_LINK_ENV_OPENBOX);
+        obt_paths_unref(paths);
+    }
+
+    apps_menu = menu_new(MENU_NAME, _("Applications"), TRUE, NULL);
+    menu_set_update_func(apps_menu, self_update);
+    menu_set_cleanup_func(apps_menu, self_cleanup);
+    menu_set_execute_func(apps_menu, menu_execute);
+    menu_set_destroy_func(apps_menu, self_destroy);
+}
+
+void apps_menu_shutdown(gboolean reconfig)
+{
+    /* freed by the hash table */
+}
diff --git a/openbox/apps_menu.h b/openbox/apps_menu.h
new file mode 100644 (file)
index 0000000..ca219c3
--- /dev/null
@@ -0,0 +1,25 @@
+/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
+
+   apps_menu.h for the Openbox window manager
+   Copyright (c) 2011        Dana Jansens
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   See the COPYING file for a copy of the GNU General Public License.
+*/
+
+#ifndef ob__apps_menu_h
+#define ob__apps_menu_h
+
+void apps_menu_startup(gboolean reconfig);
+void apps_menu_shutdown(gboolean reconfig);
+
+#endif
index c97fb56bd5fec2049479999708f016ae13b86bdf..2befac3adb794ec006eda6de28959044e90d91b8 100644 (file)
@@ -31,6 +31,7 @@
 #include "geom.h"
 #include "misc.h"
 #include "client_menu.h"
+#include "apps_menu.h"
 #include "client_list_menu.h"
 #include "client_list_combined_menu.h"
 #include "gettext.h"
@@ -67,6 +68,7 @@ void menu_startup(gboolean reconfig)
     menu_hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
                                       (GDestroyNotify)menu_destroy_hash_value);
 
+    apps_menu_startup(reconfig);
     client_list_menu_startup(reconfig);
     client_list_combined_menu_startup(reconfig);
     client_menu_startup();
@@ -119,6 +121,7 @@ void menu_shutdown(gboolean reconfig)
 
     client_list_combined_menu_shutdown(reconfig);
     client_list_menu_shutdown(reconfig);
+    apps_menu_shutdown(reconfig);
 
     g_hash_table_destroy(menu_hash);
     menu_hash = NULL;