~charlesk/appmenu-gtk/lp-788640

« back to all changes in this revision

Viewing changes to src/bridge.c

  • Committer: Cody Russell
  • Date: 2010-05-27 15:05:31 UTC
  • Revision ID: crussell@canonical.com-20100527150531-dwzdair2jdlc6mv0
Window registration

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <dbus/dbus-glib-bindings.h>
32
32
 
33
33
#include <gtk/gtk.h>
 
34
#include <gdk/gdkx.h>
 
35
 
34
36
#include <libdbusmenu-glib/menuitem.h>
35
37
#include <libdbusmenu-glib/server.h>
36
38
 
56
58
  DbusmenuMenuitem *root;
57
59
};
58
60
 
 
61
static DBusGProxy *dbusproxy = NULL;
 
62
 
59
63
G_DEFINE_DYNAMIC_TYPE(AppMenuBridge, app_menu_bridge, GTK_TYPE_MENU_PROXY)
60
64
 
61
65
static void
190
194
}
191
195
 
192
196
static void
 
197
toplevel_realized (GtkWidget *widget,
 
198
                   gpointer   user_data)
 
199
{
 
200
  org_ayatana_WindowMenu_Registrar_register_window (dbusproxy,
 
201
                                                    GDK_WINDOW_XID (gtk_widget_get_window (widget)),
 
202
                                                    APP_MENU_PATH,
 
203
                                                    NULL);
 
204
}
 
205
 
 
206
static void
193
207
app_menu_bridge_insert (GtkMenuProxy *proxy,
194
208
                        GtkWidget    *parent,
195
209
                        GtkWidget    *child,
196
210
                        guint         position)
197
211
{
 
212
  static gboolean   window_registered = FALSE;
198
213
  AppMenuBridge    *bridge;
199
214
  DbusmenuMenuitem *item;
200
215
  GtkWidget        *submenu;
206
221
  if (!gtk_widget_get_visible (child))
207
222
    return;
208
223
 
 
224
  if (!window_registered && GTK_IS_MENU_BAR (parent))
 
225
    {
 
226
      GtkWidget *toplevel = gtk_widget_get_toplevel (parent);
 
227
 
 
228
      g_signal_connect (toplevel, "realize",
 
229
                        G_CALLBACK (toplevel_realized),
 
230
                        NULL);
 
231
    }
209
232
 
210
233
  bridge = APP_MENU_BRIDGE (proxy);
211
234
 
292
315
 
293
316
  if (!registered)
294
317
    {
295
 
      DBusGProxy *proxy;
296
318
      DBusGConnection *connection;
297
319
 
298
 
      g_print ("** About to register...\n");
299
 
 
300
320
      connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
301
321
 
302
322
      g_return_if_fail (connection != NULL);
303
323
 
304
 
      proxy = dbus_g_proxy_new_for_name_owner (connection,
305
 
                                               APP_MENU_DBUS_NAME,
306
 
                                               APP_MENU_DBUS_OBJECT,
307
 
                                               APP_MENU_INTERFACE,
308
 
                                               NULL);
309
 
 
310
 
      g_return_if_fail (proxy != NULL);
311
 
 
312
 
      org_ayatana_WindowMenu_Registrar_register_window (proxy,
313
 
                                                        0,
314
 
                                                        APP_MENU_PATH,
315
 
                                                        NULL);
 
324
      dbusproxy = dbus_g_proxy_new_for_name_owner (connection,
 
325
                                                   APP_MENU_DBUS_NAME,
 
326
                                                   APP_MENU_DBUS_OBJECT,
 
327
                                                   APP_MENU_INTERFACE,
 
328
                                                   NULL);
 
329
 
 
330
      g_return_if_fail (dbusproxy != NULL);
316
331
 
317
332
      app_menu_bridge_register_type (G_TYPE_MODULE (module));
318
333