[PATCH] emit signals when workspaces are added, removed or activated



3 signals added, plus GLib marshal code
---
 configure.in              |    3 ++
 src/Makefile.am           |   36 +++++++++++++++++++++++++++-
 src/core/screen.c         |   55 ++++++++++++++++++++++++++++++++++++++++++++-
 src/core/workspace.c      |    3 ++
 src/include/screen.h      |    3 ++
 src/metacity-marshal.list |    1 +
 6 files changed, 98 insertions(+), 3 deletions(-)
 create mode 100644 src/metacity-marshal.list

diff --git a/configure.in b/configure.in
index e777c1d..75910fd 100644
--- a/configure.in
+++ b/configure.in
@@ -46,6 +46,9 @@ AC_HEADER_STDC
 AC_LIBTOOL_WIN32_DLL
 AM_PROG_LIBTOOL
 
+# Sets GLIB_GENMARSHAL and GLIB_MKENUMS
+AM_PATH_GLIB_2_0()
+
 #### Integer sizes
 
 AC_CHECK_SIZEOF(char)
diff --git a/src/Makefile.am b/src/Makefile.am
index 5e44e4f..95f4023 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,6 +8,10 @@ endif
 
 INCLUDES= METACITY_CFLAGS@ -I $(srcdir)/include -I$(srcdir)/compositor -DMETACITY_LIBEXECDIR=\"$(libexecdir)\" -DHOST_ALIAS=\"@HOST_ALIAS \" -DMETACITY_LOCALEDIR=\"$(prefix)/@DATADIRNAME@/locale\" -DMETACITY_PKGDATADIR=\"$(pkgdatadir)\" -DMETACITY_DATADIR=\"$(datadir)\" -DG_LOG_DOMAIN=\"metacity\" -DSN_API_NOT_YET_FROZEN=1 -DMETACITY_MAJOR_VERSION=$(METACITY_MAJOR_VERSION) -DMETACITY_MINOR_VERSION=$(METACITY_MINOR_VERSION) -DMETACITY_MICRO_VERSION=$(METACITY_MICRO_VERSION) -DMETACITY_CLUTTER_PLUGIN_API_VERSION=$(METACITY_CLUTTER_PLUGIN_API_VERSION) -DMETACITY_PKGLIBDIR=\"$(pkglibdir)\" -DMUTTER_PLUGIN_DIR=\"@MUTTER_PLUGIN_DIR \"
 
+metacity_built_sources = \
+	metacity-marshal.h \
+	metacity-marshal.c
+
 metacity_SOURCES= 			\
 	core/async-getprop.c			\
 	core/async-getprop.h			\
@@ -100,7 +104,8 @@ metacity_SOURCES= 			\
 	ui/themewidget.c			\
 	ui/themewidget.h			\
 	ui/ui.c					\
-	include/all-keybindings.h
+	include/all-keybindings.h   \
+	$(metacity_built_sources)
 
 if WITH_CLUTTER
 metacity_SOURCES += 				\
@@ -293,5 +298,32 @@ EXTRA_DIST=$(desktopfiles_files) 	\
 	$(schema_in_files)		\
 	$(xml_in_files)			\
 	libmetacity-private.pc.in	\
-	metacity-plugins.pc.in
+	metacity-plugins.pc.in  \
+	metacity-marshal.list
+
+BUILT_SOURCES += $(metacity_built_sources)
+METACITY_STAMP_FILES = stamp-metacity-marshal.h
+
+SHELL_STAMP_FILES = stamp-shell-marshal.h
+CLEANFILES += $(SHELL_STAMP_FILES)
+
+metacity-marshal.h: stamp-metacity-marshal.h
+	@true
+stamp-metacity-marshal.h: Makefile metacity-marshal.list
+	$(GLIB_GENMARSHAL) \
+		--prefix=_metacity_marshal \
+		--header \
+	$(srcdir)/metacity-marshal.list > xgen-tmh && \
+	(cmp -s xgen-tmh metacity-marshal.h || cp -f xgen-tmh metacity-marshal.h) && \
+	rm -f xgen-tmh && \
+	echo timestamp > $(@F)
+
+metacity-marshal.c: Makefile metacity-marshal.list
+	(echo "#include \"metacity-marshal.h\"" ; \
+	 $(GLIB_GENMARSHAL) \
+		--prefix=_metacity_marshal \
+		--body \
+	 $(srcdir)/metacity-marshal.list ) > xgen-tmc && \
+	cp -f xgen-tmc metacity-marshal.c && \
+	rm -f xgen-tmc
 
diff --git a/src/core/screen.c b/src/core/screen.c
index ec2d84f..08accad 100644
--- a/src/core/screen.c
+++ b/src/core/screen.c
@@ -38,6 +38,7 @@
 #include "stack.h"
 #include "xprops.h"
 #include "compositor.h"
+#include "metacity-marshal.h"
 
 #ifdef HAVE_SOLARIS_XINERAMA
 #include <X11/extensions/xinerama.h>
@@ -78,6 +79,9 @@ enum
 {
   RESTACKED,
   TOGGLE_RECORDING,
+  WORKSPACE_ADDED,
+  WORKSPACE_REMOVED,
+  WORKSPACE_SWITCHED,
 
   LAST_SIGNAL
 };
@@ -153,6 +157,40 @@ meta_screen_class_init (MetaScreenClass *klass)
                             "Number of workspaces",
                             1, G_MAXINT, 1,
                             G_PARAM_READABLE);
+                            
+  screen_signals[WORKSPACE_ADDED] =
+    g_signal_new ("workspace-added",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__INT,
+                  G_TYPE_NONE,
+                  1,
+                  G_TYPE_INT);
+
+  screen_signals[WORKSPACE_REMOVED] =
+    g_signal_new ("workspace-removed",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__INT,
+                  G_TYPE_NONE,
+                  1,
+                  G_TYPE_INT);
+
+  screen_signals[WORKSPACE_SWITCHED] =
+    g_signal_new ("workspace-switched",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL, NULL,
+                  _metacity_marshal_VOID__INT_UINT,
+                  G_TYPE_NONE,
+                  2,
+                  G_TYPE_INT,
+                  G_TYPE_UINT);
 
   screen_signals[TOGGLE_RECORDING] =
     g_signal_new ("toggle-recording",
@@ -1207,6 +1245,7 @@ meta_screen_remove_workspace (MetaScreen *screen, MetaWorkspace *workspace,
   GList         *l;
   MetaWorkspace *neighbour = NULL;
   GList         *next = NULL;
+  int index;
 
   l = screen->workspaces;
   while (l)
@@ -1242,6 +1281,9 @@ meta_screen_remove_workspace (MetaScreen *screen, MetaWorkspace *workspace,
   if (workspace == screen->active_workspace)
     meta_workspace_activate (neighbour, timestamp);
 
+  /* To emit the signal after removing the workspace */
+  index = meta_workspace_index (workspace);
+
   /* This also removes the workspace from the screens list */
   meta_workspace_remove (workspace);
 
@@ -1258,7 +1300,8 @@ meta_screen_remove_workspace (MetaScreen *screen, MetaWorkspace *workspace,
     }
 
   meta_screen_queue_workarea_recalc (screen);
-
+  
+  g_signal_emit (screen, screen_signals[WORKSPACE_REMOVED], 0, index); 
   g_object_notify (G_OBJECT (screen), "n-workspaces");
 }
 
@@ -1294,6 +1337,8 @@ meta_screen_append_new_workspace (MetaScreen *screen, gboolean activate,
 
   meta_screen_queue_workarea_recalc (screen);
 
+  g_signal_emit (screen, screen_signals[WORKSPACE_ADDED],
+                 0, meta_workspace_index (w)); 
   g_object_notify (G_OBJECT (screen), "n-workspaces");
 
   return w;
@@ -3072,3 +3117,11 @@ meta_screen_restacked (MetaScreen *screen)
 {
   g_signal_emit (screen, screen_signals[RESTACKED], 0);
 }
+
+void
+meta_screen_workspace_switched (MetaWorkspace *workspace, guint32 timestamp)
+{
+  g_signal_emit (workspace->screen, screen_signals[WORKSPACE_SWITCHED], 0,
+                 meta_workspace_index (workspace), timestamp);
+}
+
diff --git a/src/core/workspace.c b/src/core/workspace.c
index f324c6e..6ab1659 100644
--- a/src/core/workspace.c
+++ b/src/core/workspace.c
@@ -46,6 +46,7 @@ static void free_this                    (gpointer candidate,
 
 G_DEFINE_TYPE (MetaWorkspace, meta_workspace, G_TYPE_OBJECT);
 
+/* Signals */
 enum
 {
   WINDOW_ADDED,
@@ -525,6 +526,8 @@ meta_workspace_activate_with_focus (MetaWorkspace *workspace,
     meta_compositor_switch_workspace (comp, screen, old, workspace, direction);
   }
 #endif
+
+  meta_screen_workspace_switched (workspace, timestamp);
 }
 
 void
diff --git a/src/include/screen.h b/src/include/screen.h
index 3bdcf16..4e9ad9f 100644
--- a/src/include/screen.h
+++ b/src/include/screen.h
@@ -74,4 +74,7 @@ int meta_screen_get_active_workspace_index (MetaScreen *screen);
 
 MetaWorkspace * meta_screen_get_active_workspace (MetaScreen *screen);
 
+void meta_screen_workspace_switched (MetaWorkspace *workspace,
+                                     guint32        timestamp);
+
 #endif
diff --git a/src/metacity-marshal.list b/src/metacity-marshal.list
new file mode 100644
index 0000000..1bd9a2a
--- /dev/null
+++ b/src/metacity-marshal.list
@@ -0,0 +1 @@
+VOID:INT,UINT
-- 
1.6.0.4


--=-z9zRogdeF10FkDXul25g--




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