Merge lp:~mterry/appmenu-gtk/fix-alt-shortcuts into lp:appmenu-gtk/0.4

Proposed by Michael Terry on 2011-03-09
Status: Merged
Approved by: Ted Gould on 2011-03-10
Approved revision: 129
Merged at revision: 127
Proposed branch: lp:~mterry/appmenu-gtk/fix-alt-shortcuts
Merge into: lp:appmenu-gtk/0.4
Diff against target: 110 lines (+16/-42)
1 file modified
src/bridge.c (+16/-42)
To merge this branch: bzr merge lp:~mterry/appmenu-gtk/fix-alt-shortcuts
Reviewer Review Type Date Requested Status
Ted Gould (community) 2011-03-09 Approve on 2011-03-10
Review via email: mp+52755@code.launchpad.net

Description of the change

When we moved the parser to dbusmenu, we forgot about the lookup table for widgets to menu items in appmenu-gtk. This lookup table is used to support key presses like Alt+F for the menus.

To fix this, I used the sorta-secret gobject data "dbusmenu-gtk-parser-cached-item" saved on GtkMenuItems by the parser to map to Dbusmenuitems. This may be considered bad?

If it is considered bad to use that string directly, we should either expose the string in a header or introduce a convenience function to dbusmenu to grab the data.

To post a comment you must log in.
Ted Gould (ted) wrote :

On Wed, 2011-03-09 at 20:12 +0000, Michael Terry wrote:
> To fix this, I used the sorta-secret gobject data "dbusmenu-gtk-parser-cached-item" saved on GtkMenuItems by the parser to map to Dbusmenuitems. This may be considered bad?
>
> If it is considered bad to use that string directly, we should either expose the string in a header or introduce a convenience function to dbusmenu to grab the data.

I think it's better to expose via API. What do you think about:

  lp:~ted/dbusmenu/get-cached-menuitem

I think that works and is API we could support for a while.

Michael Terry (mterry) wrote :

Looks fine. I updated this branch to use the new function.

128. By Michael Terry on 2011-03-10

update to use new get_cached_item function

129. By Michael Terry on 2011-03-10

whoops, remove some debugging code I accidentally committed

Ted Gould (ted) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/bridge.c'
2--- src/bridge.c 2011-03-09 15:56:32 +0000
3+++ src/bridge.c 2011-03-10 14:06:48 +0000
4@@ -75,7 +75,6 @@
5 gchar *path;
6 gboolean registered;
7 AppMenuBridge *bridge;
8- GHashTable *lookup;
9 GCancellable *cancel;
10 };
11
12@@ -108,24 +107,14 @@
13 GtkWidget *widget,
14 gpointer user_data)
15 {
16- GList *list;
17+ DbusmenuMenuitem *mi = dbusmenu_gtk_parse_get_cached_item (widget);
18
19- for (list = bridge->priv->windows; list != NULL; list = list->next)
20+ if (mi != NULL)
21 {
22- AppWindowContext *context = list->data;
23-
24- if (context->lookup)
25- {
26- DbusmenuMenuitem *mi = g_hash_table_lookup (context->lookup, widget);
27-
28- if (mi != NULL)
29- {
30- dbusmenu_menuitem_show_to_user (mi, 0);
31-
32- return;
33- }
34- }
35+ dbusmenu_menuitem_show_to_user (mi, 0);
36 }
37+
38+ return;
39 }
40
41 static void
42@@ -178,12 +167,6 @@
43 g_object_remove_weak_pointer(G_OBJECT(context->window), (gpointer *)&(context->window));
44 context->window = NULL;
45 }
46-
47- if (context->lookup != NULL)
48- {
49- g_hash_table_unref (context->lookup);
50- context->lookup = NULL;
51- }
52 }
53
54 static void
55@@ -678,7 +661,6 @@
56 {
57 context = g_new0 (AppWindowContext, 1);
58 context->bridge = bridge;
59- context->lookup = g_hash_table_new (g_direct_hash, g_direct_equal);
60 bridge->priv->windows = g_list_prepend (bridge->priv->windows, context);
61 }
62
63@@ -849,17 +831,20 @@
64 else if (GTK_IS_MENU (parent))
65 {
66 GtkWidget *attach = NULL;
67- GList *tmp = NULL;
68- AppWindowContext *context = NULL;
69
70 g_object_get (parent, "attach-widget", &attach, NULL);
71
72- /* First attempt to setup the menuitem immediately if possible. */
73- for (tmp = bridge->priv->windows; tmp != NULL; tmp = tmp->next)
74- {
75- context = (AppWindowContext *)tmp->data;
76-
77- DbusmenuMenuitem *mi = (DbusmenuMenuitem *)g_hash_table_lookup (context->lookup, attach);
78+ if (attach == NULL)
79+ {
80+ g_signal_connect (G_OBJECT (parent),
81+ "notify",
82+ G_CALLBACK (attach_notify_cb),
83+ bridge);
84+ return;
85+ }
86+ else
87+ {
88+ DbusmenuMenuitem *mi = dbusmenu_gtk_parse_get_cached_item (attach);
89
90 if (mi != NULL)
91 {
92@@ -871,18 +856,7 @@
93 position);
94 return;
95 }
96- }
97
98- if (attach == NULL)
99- {
100- g_signal_connect (G_OBJECT (parent),
101- "notify",
102- G_CALLBACK (attach_notify_cb),
103- bridge);
104- return;
105- }
106- else
107- {
108 rebuild (bridge, toplevel);
109 }
110 }

Subscribers

People subscribed via source and target branches