Sophie

Sophie

distrib > Mageia > 9 > armv7hl > by-pkgid > 70db79aeb6f762d1452a58a64b648349 > files > 5

afterstep-2.2.12-22.mga9.src.rpm

From 44c3f40ac82dc75d940e3f97a9c8569804bc2088 Mon Sep 17 00:00:00 2001
From: Sasha Vasko <sasha@aftercode.net>
Date: Sat, 23 Nov 2013 02:20:05 -0600
Subject: [PATCH 05/18] Reimplemented DBus listening to use DBusWatch
 interface. Old way don't seem to work with recent GNOME

---
 AfterStep.desktop.in        |  6 +--
 AfterStep.session           |  4 +-
 src/afterstep/afterstep.c   |  8 ++--
 src/afterstep/asinternals.h | 10 ++++-
 src/afterstep/dbus.c        | 84 ++++++++++++++++++++++++++++++++-----
 src/afterstep/events.c      | 26 ++++++++++--
 6 files changed, 113 insertions(+), 25 deletions(-)

diff --git a/AfterStep.desktop.in b/AfterStep.desktop.in
index 36eb1a39..d23ffb33 100644
--- a/AfterStep.desktop.in
+++ b/AfterStep.desktop.in
@@ -1,5 +1,5 @@
-[Window Manager]
-SessionManaged=true
+#[Window Manager]
+#SessionManaged=true
 
 [Desktop Entry]
 Name=AfterStep
@@ -7,7 +7,7 @@ Type=Application
 Comment=AfterStep is feature rich NeXTish window manager.
 # name we put on the WM spec check window
 X-GNOME-WMName=AfterStep
-# back compat only 
+# back compat only
 X-GNOME-Autostart-Phase=WindowManager
 X-GNOME-Provides=windowmanager
 X-GNOME-Autostart-Notify=true
diff --git a/AfterStep.session b/AfterStep.session
index cde67207..6861ac69 100644
--- a/AfterStep.session
+++ b/AfterStep.session
@@ -1,7 +1,7 @@
 [GNOME Session]
 Name=AfterStep
-RequiredComponents=gnome-settings-daemon;
-RequiredProviders=windowmanager;
+RequiredComponents=gnome-settings-daemon;AfterStep
+#RequiredProviders=windowmanager;
 DefaultProvider-windowmanager=AfterStep
 #Please change to your preference. Supported names are:
 #GNOME;Unity;KDE;LXDE;MATE;Razor;ROX;TDE;XFCE;Old
diff --git a/src/afterstep/afterstep.c b/src/afterstep/afterstep.c
index 2de0e148..13085713 100644
--- a/src/afterstep/afterstep.c
+++ b/src/afterstep/afterstep.c
@@ -45,7 +45,7 @@ ASFlagType AfterStepState = 0;	/* default status */
 ASFlagType AfterStepStartupFlags = 0;
 
 /* DBUS stuff is separated into dbus.c */
-int ASDBus_fd = -1;
+Bool ASDBusConnected = False;
 char *GnomeSessionClientID = NULL;
 
 /* Config : */
@@ -194,7 +194,7 @@ int main (int argc, char **argv, char **envp)
 	}
 
 
-	ASDBus_fd = asdbus_init ();
+	ASDBusConnected = asdbus_init ();
 
 	XSetWindowBackground (dpy, Scr.Root, Scr.asv->black_pixel);
 	Scr.Look.desktop_animation_tint = get_random_tint_color ();
@@ -208,7 +208,7 @@ int main (int argc, char **argv, char **envp)
 		display_progress (True, "AfterStep v.%s is starting up ...", VERSION);
 	}
 //sleep_a_millisec(1000);
-	if (ASDBus_fd >= 0) {
+	if (ASDBusConnected) {
 		show_progress ("Successfuly accured Session DBus connection.");
 		GnomeSessionClientID = asdbus_RegisterSMClient (SMClientID_string);
 		if (GnomeSessionClientID != NULL) {
@@ -922,7 +922,7 @@ void Done (Bool restart, char *command)
 	/* Really make sure that the connection is closed and cleared! */
 	XSync (dpy, 0);
 
-	if (ASDBus_fd >= 0) {
+	if (ASDBusConnected) {
 		if (GnomeSessionClientID != NULL)
 			asdbus_UnregisterSMClient (GnomeSessionClientID);
 		asdbus_shutdown ();
diff --git a/src/afterstep/asinternals.h b/src/afterstep/asinternals.h
index 81b32496..71a95851 100644
--- a/src/afterstep/asinternals.h
+++ b/src/afterstep/asinternals.h
@@ -393,7 +393,7 @@ extern int           fd_width, x_fd;
 
 extern struct ASWindow *ColormapWin;
 
-extern int 			 ASDBus_fd;
+extern int 			 ASDBusConnected;
 
 extern struct ASVector *Modules;               /* dynamically resizable array of module_t data structures */
 #define MODULES_LIST    VECTOR_HEAD(module_t,*Modules)
@@ -570,9 +570,15 @@ void desktop_cover_cleanup();
 void display_progress( Bool new_line, const char *msg_format, ... );
 
 /*************************** dbus.c ***************************************/
+typedef struct 	ASDBusFd  {
+	int fd;
+	Bool readable;
+} ASDBusFd;
+
 int asdbus_init();
+ASVector* asdbus_getFds();
 void asdbus_shutdown();
-void asdbus_process_messages ();
+void asdbus_process_messages (ASDBusFd*);
 
 char *asdbus_RegisterSMClient(const char *sm_client_id);
 void asdbus_Notify(const char *summary, const char *body, int timeout);
diff --git a/src/afterstep/dbus.c b/src/afterstep/dbus.c
index d7594d9f..c8214604 100644
--- a/src/afterstep/dbus.c
+++ b/src/afterstep/dbus.c
@@ -107,13 +107,13 @@ static ASDBusOjectDescr dbusUPower = {"Power Management Daemon", True, UPOWER_NA
 typedef struct ASDBusContext {
 	DBusConnection *system_conn;
 	DBusConnection *session_conn;
-	int watch_fd;
+	ASVector *watchFds;  // vector of ASDBusFds
 	char *gnomeSessionPath;
 	Bool sessionManagerCanShutdown;
 	int kdeSessionVersion;
 } ASDBusContext;
 
-static ASDBusContext ASDBus = { NULL, NULL, -1, NULL, False, 0 };
+static ASDBusContext ASDBus = { NULL, NULL, NULL, NULL, False, 0 };
 
 static DBusHandlerResult asdbus_handle_message (DBusConnection *,
 																								DBusMessage *, void *);
@@ -202,25 +202,89 @@ _asdbus_get_system_connection()
 	return sys_conn;
 }
 
+/******************************************************************************/
+/* Watch functions */
+/******************************************************************************/
+static dbus_bool_t add_watch(DBusWatch *w, void *data)
+{
+    	if (!dbus_watch_get_enabled(w))
+      		return TRUE;
+
+	ASDBusFd *fd = safecalloc (1, sizeof(ASDBusFd));
+	fd->fd =  dbus_watch_get_unix_fd(w);
+	unsigned int flags = dbus_watch_get_flags(w);
+	if (get_flags(flags, DBUS_WATCH_READABLE))
+		fd->readable = True;
+    /*short cond = EV_PERSIST;
+    if (flags & DBUS_WATCH_READABLE)
+        cond |= EV_READ;
+    if (flags & DBUS_WATCH_WRITABLE)
+        cond |= EV_WRITE; */
+
+      // TODO add to the list of FDs
+	dbus_watch_set_data(w, fd, NULL);
+	if (ASDBus.watchFds == NULL)
+		ASDBus.watchFds = create_asvector (sizeof(ASDBusFd*));
+
+	append_vector(ASDBus.watchFds, fd, 1);
+
+	show_progress("added dbus watch fd=%d watch=%p readable =%d\n", fd->fd, w, fd->readable);
+	return TRUE;
+}
+
+static void remove_watch(DBusWatch *w, void *data)
+{
+    ASDBusFd* fd = dbus_watch_get_data(w);
+
+    vector_remove_elem (ASDBus.watchFds, fd);
+    dbus_watch_set_data(w, NULL, NULL);
+    show_progress("removed dbus watch watch=%p\n", w);
+}
+
+static void toggle_watch(DBusWatch *w, void *data)
+{
+    show_progress("toggling dbus watch watch=%p\n", w);
+    if (dbus_watch_get_enabled(w))
+        add_watch(w, data);
+    else
+        remove_watch(w, data);
+}
+
+
 /******************************************************************************/
 /* External interfaces : */
 /******************************************************************************/
-int asdbus_init ()
+Bool asdbus_init ()
 {																/* return connection unix fd */
 	char *tmp;
-	if (!ASDBus.session_conn)
+	if (!ASDBus.session_conn) {
 		ASDBus.session_conn = _asdbus_get_session_connection();
+		if (!dbus_connection_set_watch_functions(ASDBus.session_conn, add_watch, remove_watch,  toggle_watch, ASDBus.session_conn, NULL)) {
+		 	show_error("dbus_connection_set_watch_functions() failed");
+		}
+
+	}
 
-	if (!ASDBus.system_conn)
+	if (!ASDBus.system_conn){
 		ASDBus.system_conn = _asdbus_get_system_connection();
+		/*if (!dbus_connection_set_watch_functions(ASDBus.system_conn, add_watch, remove_watch,  toggle_watch, ASDBus.system_conn, NULL)) {
+		 	show_error("dbus_connection_set_watch_functions() failed");
+		}*/
+	}
 
-	if (ASDBus.session_conn && ASDBus.watch_fd < 0)
-		dbus_connection_get_unix_fd (ASDBus.session_conn, &(ASDBus.watch_fd));
+	/*if (ASDBus.session_conn && ASDBus.watchFds == NULL){
+		//dbus_connection_get_unix_fd (ASDBus.session_conn, &(ASDBus.watch_fd));
+		//dbus_whatch_get_unix_fd (ASDBus.session_conn, &(ASDBus.watch_fd));
+	}*/
 
 	if ((tmp = getenv ("KDE_SESSION_VERSION")) != NULL)
 		ASDBus.kdeSessionVersion = atoi(tmp);
 
-	return ASDBus.watch_fd;
+	return (ASDBus.session_conn != NULL);
+}
+
+ASVector* asdbus_getFds() {
+	return ASDBus.watchFds;
 }
 
 void asdbus_shutdown ()
@@ -263,9 +327,9 @@ Bool get_gnome_autosave ()
 void asdbus_EndSessionOk ();
 
 
-void asdbus_process_messages ()
+void asdbus_process_messages (ASDBusFd* fd)
 {
-/*	show_progress ("checking Dbus messages"); */
+	show_progress ("checking Dbus messages for fd = %d", fd->fd);
 #if 1
 	while (ASDBus.session_conn) {
 		DBusMessage *msg;
diff --git a/src/afterstep/events.c b/src/afterstep/events.c
index 5588ffb3..25d03603 100644
--- a/src/afterstep/events.c
+++ b/src/afterstep/events.c
@@ -1767,6 +1767,12 @@ void afterstep_wait_pipes_input (int timeout_sec)
 	struct timeval tv;
 	struct timeval *t = NULL;
 	int max_fd = 0;
+	ASVector *asdbus_fds = NULL;
+
+	if (ASDBusConnected)
+		asdbus_fds = asdbus_getFds();
+
+
 	LOCAL_DEBUG_OUT ("waiting pipes%s", "");
 	FD_ZERO (&in_fdset);
 	FD_ZERO (&out_fdset);
@@ -1776,7 +1782,14 @@ void afterstep_wait_pipes_input (int timeout_sec)
 #define AS_FD_SET(fd,fdset) \
 	do{ if (fd>=0) { FD_SET((fd),(fdset)); if ((fd)>max_fd) max_fd = (fd);}}while(0)
 
-	AS_FD_SET (ASDBus_fd, &in_fdset);
+	if (asdbus_fds != NULL) {
+		register int i;
+		for ( i = 0 ; i < asdbus_fds->used; ++i) {
+			ASDBusFd* fd = PVECTOR_HEAD(ASDBusFd*,asdbus_fds)[i];
+			if (fd->readable)
+				AS_FD_SET (fd->fd, &in_fdset);
+		}
+	}
 	AS_FD_SET (Module_fd, &in_fdset);
 
 	if (Modules != NULL) {				/* adding all the modules pipes to our wait list */
@@ -1827,9 +1840,14 @@ void afterstep_wait_pipes_input (int timeout_sec)
 				if (has_input || has_output)
 					HandleModuleInOut (i, has_input, has_output);
 			}
-		if (ASDBus_fd >= 0)
-			if (FD_ISSET (ASDBus_fd, &in_fdset))
-				asdbus_process_messages ();
+		if (asdbus_fds != NULL) {
+			register int i;
+			for ( i = 0 ; i < asdbus_fds->used; ++i) {
+				ASDBusFd* fd = PVECTOR_HEAD(ASDBusFd*,asdbus_fds)[i];
+				if (FD_ISSET (fd->fd, &in_fdset))
+					asdbus_process_messages (fd);
+			}
+		}
 	}
 
 	/* handle timeout events */
-- 
2.22.0