[gnome-panel/wip/in-process-only: 3/3] libpanel-applet: remove support for out-of-process applets



commit b60a3dfd845ef025648063a48a9fc94f1066ff3a
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Tue Jul 26 22:46:45 2016 +0300

    libpanel-applet: remove support for out-of-process applets

 libpanel-applet/Makefile.am                        |   26 +--
 .../org.gnome.panel.TestApplet.panel-applet.in     |   10 -
 libpanel-applet/panel-applet-factory.c             |    4 -
 libpanel-applet/panel-applet-factory.h             |    1 -
 libpanel-applet/panel-applet-private.h             |    2 -
 libpanel-applet/panel-applet.c                     |  253 +-------------------
 libpanel-applet/panel-applet.h                     |   63 +-----
 libpanel-applet/panel-plug-private.h               |   32 ---
 libpanel-applet/panel-plug.c                       |   98 --------
 libpanel-applet/test-dbus-applet.c                 |  193 ---------------
 libpanel-applet/test-dbus-applet.py                |   21 --
 11 files changed, 8 insertions(+), 695 deletions(-)
---
diff --git a/libpanel-applet/Makefile.am b/libpanel-applet/Makefile.am
index 3f69ebf..cd76f5b 100644
--- a/libpanel-applet/Makefile.am
+++ b/libpanel-applet/Makefile.am
@@ -1,7 +1,6 @@
 NULL =
 
 lib_LTLIBRARIES = libpanel-applet.la
-noinst_PROGRAMS = test-dbus-applet
 
 libpanel_applet_la_CFLAGS = \
        -DGNOMELOCALEDIR=\""$(localedir)"\" \
@@ -24,9 +23,7 @@ libpanel_applet_la_SOURCES =          \
        panel-applet-factory.c          \
        panel-applet-bindings.h         \
        panel-applet-bindings.c         \
-       panel-applet-private.h          \
-       panel-plug.c                    \
-       panel-plug-private.h
+       panel-applet-private.h
 
 libpanel_applet_la_LIBADD  = \
        $(LIBPANEL_APPLET_LIBS) \
@@ -39,19 +36,7 @@ libpanel_applet_la_LDFLAGS = \
        $(AM_LDFLAGS) \
        $(NULL)
 
-test_dbus_applet_CFLAGS = \
-       -DGNOMELOCALEDIR=\""$(localedir)"\" \
-       -I$(top_builddir)/libpanel-applet \
-       $(LIBPANEL_APPLET_CFLAGS) \
-       $(WARN_CFLAGS) \
-       $(AM_CFLAGS) \
-       $(NULL)
-
-test_dbus_applet_LDADD =       \
-       $(LIBPANEL_APPLET_LIBS) \
-       libpanel-applet.la
-
-$(libpanel_applet_la_OBJECTS) $(test_dbus_applet_OBJECTS): $(BUILT_SOURCES)
+$(libpanel_applet_la_OBJECTS): $(BUILT_SOURCES)
 
 panel-applet-marshal.h: panel-applet-marshal.list $(GLIB_GENMARSHAL)
        $(AM_V_GEN)$(GLIB_GENMARSHAL) $< --header --prefix=panel_applet_marshal > $@
@@ -99,14 +84,7 @@ BUILT_SOURCES = \
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libpanel-applet.pc
 
-appletdir       = $(appletsdir)
-applet_in_files = org.gnome.panel.TestApplet.panel-applet.in
-noinst_DATA     = $(applet_in_files:.panel-applet.in=.panel-applet)
-
-@PANEL_INTLTOOL_PANEL_APPLET_RULE@
-
 EXTRA_DIST =                                           \
-       org.gnome.panel.TestApplet.panel-applet.in      \
        panel-applet-marshal.list                       \
        libpanel-applet.pc.in                   \
        libpanel-applet-uninstalled.pc.in
diff --git a/libpanel-applet/panel-applet-factory.c b/libpanel-applet/panel-applet-factory.c
index 7a66c09..9171f8a 100644
--- a/libpanel-applet/panel-applet-factory.c
+++ b/libpanel-applet/panel-applet-factory.c
@@ -26,7 +26,6 @@ struct _PanelAppletFactory {
 
        gchar     *factory_id;
        guint      n_applets;
-       gboolean   out_of_process;
        GType      applet_type;
        GClosure  *closure;
 
@@ -121,7 +120,6 @@ panel_applet_factory_applet_removed (PanelAppletFactory *factory,
 
 PanelAppletFactory *
 panel_applet_factory_new (const gchar *factory_id,
-                          gboolean     out_of_process,
                          GType        applet_type,
                          GClosure    *closure)
 {
@@ -129,7 +127,6 @@ panel_applet_factory_new (const gchar *factory_id,
 
        factory = PANEL_APPLET_FACTORY (g_object_new (PANEL_TYPE_APPLET_FACTORY, NULL));
        factory->factory_id = g_strdup (factory_id);
-       factory->out_of_process = out_of_process;
        factory->applet_type = applet_type;
        factory->closure = g_closure_ref (closure);
 
@@ -195,7 +192,6 @@ panel_applet_factory_get_applet (PanelAppletFactory    *factory,
        g_variant_get (parameters, "(&s@a{sv})", &applet_id, &props);
 
        applet = g_object_new (factory->applet_type,
-                              "out-of-process", factory->out_of_process,
                               "id", applet_id,
                               "connection", connection,
                               "closure", factory->closure,
diff --git a/libpanel-applet/panel-applet-factory.h b/libpanel-applet/panel-applet-factory.h
index 6e796ee..fdeb921 100644
--- a/libpanel-applet/panel-applet-factory.h
+++ b/libpanel-applet/panel-applet-factory.h
@@ -36,7 +36,6 @@ typedef struct _PanelAppletFactoryClass PanelAppletFactoryClass;
 
 GType               panel_applet_factory_get_type          (void) G_GNUC_CONST;
 PanelAppletFactory *panel_applet_factory_new               (const gchar        *applet_id,
-                                                            gboolean            out_of_process,
                                                             GType               applet_type,
                                                             GClosure           *closure);
 gboolean            panel_applet_factory_register_service  (PanelAppletFactory *factory);
diff --git a/libpanel-applet/panel-applet-private.h b/libpanel-applet/panel-applet-private.h
index f531542..11f58be 100644
--- a/libpanel-applet/panel-applet-private.h
+++ b/libpanel-applet/panel-applet-private.h
@@ -25,8 +25,6 @@
 
 G_BEGIN_DECLS
 
-guint32      panel_applet_get_xid           (PanelApplet *applet,
-                                             GdkScreen   *screen);
 const gchar *panel_applet_get_object_path   (PanelApplet *applet);
 GtkWidget   *panel_applet_get_applet_widget (const gchar *factory_id,
                                              guint        uid);
diff --git a/libpanel-applet/panel-applet.c b/libpanel-applet/panel-applet.c
index 005e08a..919bdf1 100644
--- a/libpanel-applet/panel-applet.c
+++ b/libpanel-applet/panel-applet.c
@@ -45,7 +45,6 @@
 #include "panel-applet-factory.h"
 #include "panel-applet-marshal.h"
 #include "panel-applet-enums.h"
-#include "panel-plug-private.h"
 
 /**
  * SECTION:applet
@@ -76,12 +75,9 @@
  */
 
 struct _PanelAppletPrivate {
-       GtkWidget         *plug;
        GtkWidget         *applet;
        GDBusConnection   *connection;
 
-       gboolean           out_of_process;
-
        char              *id;
        GClosure          *closure;
        char              *object_path;
@@ -113,7 +109,6 @@ static guint panel_applet_signals [LAST_SIGNAL];
 
 enum {
        PROP_0,
-       PROP_OUT_OF_PROCESS,
        PROP_ID,
        PROP_CLOSURE,
        PROP_CONNECTION,
@@ -1049,73 +1044,6 @@ panel_applet_can_focus (GtkWidget *widget)
        return !container_has_focusable_child (GTK_CONTAINER (widget));
 }
 
-/* Taken from libbonoboui/bonobo/bonobo-plug.c */
-static gboolean
-panel_applet_button_event (PanelApplet    *applet,
-                           GdkEventButton *event)
-{
-       GtkWidget *widget;
-       GdkWindow *window;
-       GdkWindow *socket_window;
-       XEvent     xevent;
-
-       if (!applet->priv->out_of_process)
-               return FALSE;
-
-       widget = applet->priv->plug;
-
-       if (!gtk_widget_is_toplevel (widget))
-               return FALSE;
-
-       window = gtk_widget_get_window (widget);
-       socket_window = gtk_plug_get_socket_window (GTK_PLUG (widget));
-
-       if (event->type == GDK_BUTTON_PRESS) {
-               GdkDisplay *display;
-               GdkSeat *seat;
-
-               xevent.xbutton.type = ButtonPress;
-
-               display = gdk_display_get_default ();
-               seat = gdk_display_get_default_seat (display);
-
-               /* X does an automatic pointer grab on button press
-                * if we have both button press and release events
-                * selected.
-                * We don't want to hog the pointer on our parent.
-                */
-               gdk_seat_ungrab (seat);
-       } else {
-               xevent.xbutton.type = ButtonRelease;
-       }
-
-       xevent.xbutton.display     = GDK_WINDOW_XDISPLAY (window);
-       xevent.xbutton.window      = GDK_WINDOW_XID (socket_window);
-       xevent.xbutton.root        = GDK_WINDOW_XID (gdk_screen_get_root_window
-                                                        (gdk_window_get_screen (window)));
-       /*
-        * FIXME: the following might cause
-        *        big problems for non-GTK apps
-        */
-       xevent.xbutton.x           = 0;
-       xevent.xbutton.y           = 0;
-       xevent.xbutton.x_root      = 0;
-       xevent.xbutton.y_root      = 0;
-       xevent.xbutton.state       = event->state;
-       xevent.xbutton.button      = event->button;
-       xevent.xbutton.same_screen = TRUE; /* FIXME ? */
-
-       gdk_error_trap_push ();
-
-       XSendEvent (GDK_WINDOW_XDISPLAY (window),
-                   GDK_WINDOW_XID (socket_window),
-                   False, NoEventMask, &xevent);
-
-       gdk_error_trap_pop_ignored ();
-
-       return TRUE;
-}
-
 static gboolean
 panel_applet_button_press (GtkWidget      *widget,
                           GdkEventButton *event)
@@ -1142,16 +1070,14 @@ panel_applet_button_press (GtkWidget      *widget,
                return TRUE;
        }
 
-       return panel_applet_button_event (applet, event);
+       return FALSE;
 }
 
 static gboolean
 panel_applet_button_release (GtkWidget      *widget,
                             GdkEventButton *event)
 {
-       PanelApplet *applet = PANEL_APPLET (widget);
-
-       return panel_applet_button_event (applet, event);
+       return FALSE;
 }
 
 static void
@@ -1342,9 +1268,6 @@ panel_applet_get_property (GObject    *object,
        PanelApplet *applet = PANEL_APPLET (object);
 
        switch (prop_id) {
-       case PROP_OUT_OF_PROCESS:
-               g_value_set_boolean (value, applet->priv->out_of_process);
-               break;
        case PROP_ID:
                g_value_set_string (value, applet->priv->id);
                break;
@@ -1394,9 +1317,6 @@ panel_applet_set_property (GObject      *object,
        PanelApplet *applet = PANEL_APPLET (object);
 
        switch (prop_id) {
-       case PROP_OUT_OF_PROCESS:
-               applet->priv->out_of_process = g_value_get_boolean (value);
-               break;
        case PROP_ID:
                applet->priv->id = g_value_dup_string (value);
                break;
@@ -1531,33 +1451,6 @@ panel_applet_init (PanelApplet *applet)
        panel_applet_composited_changed (GTK_WIDGET (applet));
 }
 
-static GObject *
-panel_applet_constructor (GType                  type,
-                          guint                  n_construct_properties,
-                          GObjectConstructParam *construct_properties)
-{
-       GObject     *object;
-       PanelApplet *applet;
-
-       object = G_OBJECT_CLASS (panel_applet_parent_class)->constructor (type,
-                                                                         n_construct_properties,
-                                                                         construct_properties);
-       applet = PANEL_APPLET (object);
-
-       if (!applet->priv->out_of_process)
-               return object;
-
-       applet->priv->plug = panel_plug_new ();
-
-       g_signal_connect_swapped (G_OBJECT (applet->priv->plug), "embedded",
-                                     G_CALLBACK (panel_applet_setup),
-                                     applet);
-
-       gtk_container_add (GTK_CONTAINER (applet->priv->plug), GTK_WIDGET (applet));
-
-       return object;
-}
-
 static void
 panel_applet_constructed (GObject *object)
 {
@@ -1580,7 +1473,6 @@ panel_applet_class_init (PanelAppletClass *klass)
 
        gobject_class->get_property = panel_applet_get_property;
        gobject_class->set_property = panel_applet_set_property;
-       gobject_class->constructor = panel_applet_constructor;
        gobject_class->constructed = panel_applet_constructed;
         gobject_class->finalize = panel_applet_finalize;
 
@@ -1596,19 +1488,6 @@ panel_applet_class_init (PanelAppletClass *klass)
        widget_class->focus = panel_applet_focus;
 
        /**
-        * PanelApplet:out-of-process: (skip)
-        *
-        * Implementation detail.
-        **/
-       g_object_class_install_property (gobject_class,
-                                        PROP_OUT_OF_PROCESS,
-                                        g_param_spec_boolean ("out-of-process",
-                                                              "out-of-process",
-                                                              "out-of-process",
-                                                              TRUE,
-                                                              G_PARAM_CONSTRUCT_ONLY |
-                                                              G_PARAM_READWRITE));
-       /**
         * PanelApplet:id: (skip)
         *
         * Implementation detail.
@@ -1914,70 +1793,8 @@ panel_applet_register_object (PanelApplet *applet)
        }
 }
 
-static void
-panel_applet_factory_main_finalized (gpointer data,
-                                    GObject *object)
-{
-       gtk_main_quit ();
-
-       if (introspection_data) {
-               g_dbus_node_info_unref (introspection_data);
-               introspection_data = NULL;
-       }
-}
-
-static int (*_x_error_func) (Display *, XErrorEvent *);
-
-static int
-_x_error_handler (Display *display, XErrorEvent *error)
-{
-       if (!error->error_code)
-               return 0;
-
-       /* If we got a BadDrawable or a BadWindow, we ignore it for now.
-        * FIXME: We need to somehow distinguish real errors from
-        * X-server-induced errors. Keeping a list of windows for which we
-        * will ignore BadDrawables would be a good idea. */
-       if (error->error_code == BadDrawable ||
-           error->error_code == BadWindow)
-               return 0;
-
-       return _x_error_func (display, error);
-}
-
-/*
- * To do graphical embedding in the X window system, GNOME Panel
- * uses the classic foreign-window-reparenting trick. The
- * GtkPlug/GtkSocket widgets are used for this purpose. However,
- * serious robustness problems arise if the GtkSocket end of the
- * connection unexpectedly dies. The X server sends out DestroyNotify
- * events for the descendants of the GtkPlug (i.e., your embedded
- * component's windows) in effectively random order. Furthermore, if
- * you happened to be drawing on any of those windows when the
- * GtkSocket was destroyed (a common state of affairs), an X error
- * will kill your application.
- *
- * To solve this latter problem, GNOME Panel sets up its own X error
- * handler which ignores certain X errors that might have been
- * caused by such a scenario. Other X errors get passed to gdk_x_error
- * normally.
- */
-static void
-_panel_applet_setup_x_error_handler (void)
-{
-       static gboolean error_handler_setup = FALSE;
-
-       if (error_handler_setup)
-               return;
-
-       error_handler_setup = TRUE;
-
-       _x_error_func = XSetErrorHandler (_x_error_handler);
-}
-
 static int
 _panel_applet_factory_main_internal (const gchar               *factory_id,
-                                    gboolean                   out_process,
                                     GType                      applet_type,
                                     PanelAppletFactoryCallback callback,
                                     gpointer                   user_data)
@@ -1989,21 +1806,11 @@ _panel_applet_factory_main_internal (const gchar               *factory_id,
        g_return_val_if_fail (callback != NULL, 1);
        g_assert (g_type_is_a (applet_type, PANEL_TYPE_APPLET));
 
-       if (out_process)
-               _panel_applet_setup_x_error_handler ();
-
        closure = g_cclosure_new (G_CALLBACK (callback), user_data, NULL);
-       factory = panel_applet_factory_new (factory_id, out_process, applet_type, closure);
+       factory = panel_applet_factory_new (factory_id, applet_type, closure);
        g_closure_unref (closure);
 
        if (panel_applet_factory_register_service (factory)) {
-               if (out_process) {
-                       g_object_weak_ref (G_OBJECT (factory),
-                                          panel_applet_factory_main_finalized,
-                                          NULL);
-                       gtk_main ();
-               }
-
                return 0;
        }
 
@@ -2013,42 +1820,6 @@ _panel_applet_factory_main_internal (const gchar               *factory_id,
 }
 
 /**
- * panel_applet_factory_main:
- * @factory_id: identifier of an applet factory.
- * @applet_type: GType of the applet this factory creates.
- * @callback: (scope call): callback to be called when a new applet is created.
- * @data: (closure): callback data.
- *
- * Creates the applet factory for @factory_id, so that the factory can create
- * instances of the applet types it is associated with.
- *
- * Applet instances created by the applet factory will use @applet_type as
- * GType. Unless you subclass #PanelApplet, you should use %PANEL_TYPE_APPLET
- * as @applet_type.
- *
- * On creation of the applet instances, @callback is called to setup the
- * applet. If @callback returns %FALSE, the creation of the applet instance is
- * cancelled.
- *
- * If using C, it is recommended to use #PANEL_APPLET_OUT_PROCESS_FACTORY
- * instead as it will create a main() function for you.
- *
- * It can only be used once, and is incompatible with the use of
- * %PANEL_APPLET_IN_PROCESS_FACTORY and %PANEL_APPLET_OUT_PROCESS_FACTORY.
- *
- * Returns: 0 on success, 1 if there is an error.
- **/
-int
-panel_applet_factory_main (const gchar               *factory_id,
-                          GType                      applet_type,
-                          PanelAppletFactoryCallback callback,
-                          gpointer                   data)
-{
-       return _panel_applet_factory_main_internal (factory_id, TRUE, applet_type,
-                                                   callback, data);
-}
-
-/**
  * panel_applet_factory_setup_in_process: (skip)
  * @factory_id: identifier of an applet factory.
  * @applet_type: GType of the applet this factory creates.
@@ -2066,8 +1837,7 @@ panel_applet_factory_main (const gchar               *factory_id,
  * applet. If @callback returns %FALSE, the creation of the applet instance is
  * cancelled.
  *
- * It can only be used once, and is incompatible with the use of
- * %PANEL_APPLET_IN_PROCESS_FACTORY and %PANEL_APPLET_OUT_PROCESS_FACTORY.
+ * It can only be used once.
  *
  * Returns: 0 on success, 1 if there is an error.
  **/
@@ -2077,23 +1847,10 @@ panel_applet_factory_setup_in_process (const gchar               *factory_id,
                                       PanelAppletFactoryCallback callback,
                                       gpointer                   data)
 {
-       return _panel_applet_factory_main_internal (factory_id, FALSE, applet_type,
+       return _panel_applet_factory_main_internal (factory_id, applet_type,
                                                    callback, data);
 }
 
-guint32
-panel_applet_get_xid (PanelApplet *applet,
-                     GdkScreen   *screen)
-{
-       if (applet->priv->out_of_process == FALSE)
-               return 0;
-
-       gtk_window_set_screen (GTK_WINDOW (applet->priv->plug), screen);
-       gtk_widget_show (applet->priv->plug);
-
-       return gtk_plug_get_id (GTK_PLUG (applet->priv->plug));
-}
-
 const gchar *
 panel_applet_get_object_path (PanelApplet *applet)
 {
diff --git a/libpanel-applet/panel-applet.h b/libpanel-applet/panel-applet.h
index 3899de5..d2b5391 100644
--- a/libpanel-applet/panel-applet.h
+++ b/libpanel-applet/panel-applet.h
@@ -194,11 +194,6 @@ void               panel_applet_setup_menu_from_resource (PanelApplet    *applet
                                                          GSimpleActionGroup *action_group,
                                                          const gchar        *translation_domain);
 
-int                panel_applet_factory_main          (const gchar               *factory_id,
-                                                      GType                       applet_type,
-                                                      PanelAppletFactoryCallback  callback,
-                                                      gpointer                    data);
-
 int                panel_applet_factory_setup_in_process (const gchar               *factory_id,
                                                          GType                      applet_type,
                                                          PanelAppletFactoryCallback callback,
@@ -228,61 +223,6 @@ int                panel_applet_factory_setup_in_process (const gchar
 #endif /* !defined(ENABLE_NLS) */
 
 /**
- * PANEL_APPLET_OUT_PROCESS_FACTORY:
- * @factory_id: identifier of an applet factory.
- * @type: GType of the applet this factory creates.
- * @callback: (scope call): a %PanelAppletFactoryCallback to be called
- *     when a new applet is created.
- * @data: (closure): callback data.
- *
- * Convenience macro providing a main() function for an out-of-process applet.
- * Internally, it will call panel_applet_factory_main() to create the
- * @factory_id applet factory.
- *
- * Applet instances created by the applet factory will use @applet_type as
- * GType. Unless you subclass #PanelApplet, you should use %PANEL_TYPE_APPLET
- * as @applet_type.
- *
- * On creation of the applet instances, @callback is called to setup the
- * applet. If @callback returns %FALSE, the creation of the applet instance is
- * cancelled.
- *
- * It can only be used once, and is incompatible with the use of
- * %PANEL_APPLET_IN_PROCESS_FACTORY and panel_applet_factory_main().
- **/
-#define PANEL_APPLET_OUT_PROCESS_FACTORY(factory_id, type, callback, data)      \
-int main (int argc, char *argv [])                                             \
-{                                                                              \
-       GOptionContext *context;                                                \
-       GError         *error;                                                  \
-       int             retval;                                                 \
-                                                                               \
-       _PANEL_APPLET_SETUP_GETTEXT (TRUE);                                     \
-                                                                               \
-       context = g_option_context_new ("");                                    \
-       g_option_context_add_group (context, gtk_get_option_group (TRUE));      \
-                                                                               \
-       error = NULL;                                                           \
-       if (!g_option_context_parse (context, &argc, &argv, &error)) {          \
-               if (error) {                                                    \
-                       g_printerr ("Cannot parse arguments: %s.\n",            \
-                                   error->message);                            \
-                       g_error_free (error);                                   \
-               } else                                                          \
-                       g_printerr ("Cannot parse arguments.\n");               \
-               g_option_context_free (context);                                \
-               return 1;                                                       \
-       }                                                                       \
-                                                                               \
-       gtk_init (&argc, &argv);                                                \
-                                                                                \
-        retval = panel_applet_factory_main (factory_id, type, callback, data);  \
-       g_option_context_free (context);                                        \
-                                                                               \
-       return retval;                                                          \
-}
-
-/**
  * PANEL_APPLET_IN_PROCESS_FACTORY:
  * @factory_id: identifier of an applet factory.
  * @type: GType of the applet this factory creates.
@@ -301,8 +241,7 @@ int main (int argc, char *argv [])                                          \
  * applet. If @callback returns %FALSE, the creation of the applet instance is
  * cancelled.
  *
- * It can only be used once, and is incompatible with the use of
- * %PANEL_APPLET_OUT_PROCESS_FACTORY and panel_applet_factory_main().
+ * It can only be used once.
  **/
 #define PANEL_APPLET_IN_PROCESS_FACTORY(factory_id, type, callback, data)       \
 gboolean _panel_applet_shlib_factory (void);                                   \


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]