diff options
author | test-tools <test-tools> | 2006-10-15 16:09:40 +0000 |
---|---|---|
committer | test-tools <test-tools> | 2006-10-15 16:09:40 +0000 |
commit | e67bef3c65770c4c25271c0bda8b1255a48dcced (patch) | |
tree | 80f1681d8051b34ca72eac2e7547fb171f3a0a1b /src | |
parent | 8e80a4ea3579007123ec6de91cd6eef656849b71 (diff) | |
download | beryl-manager-e67bef3c65770c4c25271c0bda8b1255a48dcced.tar.gz beryl-manager-e67bef3c65770c4c25271c0bda8b1255a48dcced.tar.bz2 |
beryl-manager: Pidfile gone, we can check this via X (Works then also remote),
on a ClientMessage we have the popup (Maybe add additional checks if unwanted
popup apeear in the wild.). Multiple DISPLAY fixes.
It now, per default don't replaces a running Window Manager at start
(but you can use --force-window-manager).
--force-decorator effect stuff untested/disfunctional at the moment...
Some gdk_thread fixes, at least according to documentation.
At least lesser startup crashes in reloading WMs.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 200 |
1 files changed, 138 insertions, 62 deletions
@@ -26,6 +26,7 @@ #define manager_error(String) g_critical("%s: %s", String, g_strerror(errno)) Atom wmAtom; +Atom PopupRunning; GMutex * mutx; EggTrayIcon * mainIcon; GtkWidget * menu; @@ -43,7 +44,6 @@ gboolean useFB=TRUE; gint WM=0; gint fallBackWM=0; gint DM=0; -gchar* pidfile; gchar* displayname; typedef struct _DMInfo { @@ -95,6 +95,8 @@ GtkWidget * reloadDecoratorItem; void launchWM(); void showMenu(guint,guint32); +static Window Window_With_Name (Display * dpy, Window top, char *name); + static void usage (const char *programName) @@ -117,6 +119,27 @@ signalHandler (int sig) break; } } + +gchar* display_part(const gchar *p) +{ + gchar *name = g_strdup(p); + gchar *tmp; + + if ((tmp = g_strrstr(name,":"))) { + *tmp++ = 0; + tmp = g_strdup(tmp); + g_free(name); + name = tmp; + } + + if ((tmp = g_strrstr(name,"."))) { + *tmp = 0; + } + + return name; +} + + void beryl_manager_log_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, @@ -256,7 +279,7 @@ gboolean is_running(const gchar * command) { if (strncmp(cp,"DISPLAY=",8)==0) { - if (strcmp(cp+8,displayname)==0) + if (strcmp(display_part(cp+8),displayname)==0) { g_strfreev(pidlist); g_free(pret); @@ -289,6 +312,11 @@ void showMenu(guint button,guint32 time) { gtk_menu_popup(GTK_MENU(menu),NULL,NULL,NULL,NULL,0,time); } +gboolean popupClient(GtkWidget * w, GdkEventButton * e, gpointer d) +{ + showMenu(0,gtk_get_current_event_time()); + return TRUE; +} gboolean buttonUp(GtkWidget * w, GdkEventButton * e, gpointer d) { if (hasMouse) @@ -734,7 +762,6 @@ void init_menu() gtk_menu_shell_append(GTK_MENU_SHELL(menu),mitem); gtk_widget_show(mitem); g_signal_connect(mitem,"activate",G_CALLBACK(startApp),"beryl-settings"); - mitem = gtk_image_menu_item_new_with_label(_("Emerald Theme Manager")); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mitem), make_image(PIXMAPS_DIR "/emerald-theme-manager-icon.png")); @@ -872,6 +899,7 @@ void init_menu() mitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT,NULL); g_signal_connect(mitem,"activate",G_CALLBACK(quitMe),NULL); + g_signal_connect(mitem,"client-event",G_CALLBACK(popupClient),NULL); gtk_menu_shell_append(GTK_MENU_SHELL(menu),mitem); gtk_widget_show(mitem); } @@ -892,10 +920,12 @@ void init_widgets() icon = gtk_image_new_from_pixbuf(pbuf); gtk_container_add(GTK_CONTAINER(mainIcon),evbox); gtk_container_add(GTK_CONTAINER(evbox),icon); - //g_signal_connect(evbox,"button-press-event",G_CALLBACK(buttonDown),NULL); g_signal_connect(evbox,"button-release-event",G_CALLBACK(buttonUp),NULL); g_signal_connect(evbox,"enter-notify-event",G_CALLBACK(enterNotify),NULL); g_signal_connect(evbox,"leave-notify-event",G_CALLBACK(leaveNotify),NULL); + g_signal_connect(evbox,"client-event",G_CALLBACK(popupClient),NULL); + g_signal_connect(icon,"client-event",G_CALLBACK(popupClient),NULL); + g_signal_connect(mainIcon,"client-event",G_CALLBACK(popupClient),NULL); gtk_widget_show_all(GTK_WIDGET(mainIcon)); init_menu(); } @@ -940,6 +970,9 @@ int main(int argc, char ** argv) gchar *buffer; gboolean daemon_mode = TRUE; Display * d; + gboolean force_window_manager = FALSE; + gboolean force_decorator = FALSE; + Window running_window; //Intialise error handler g_log_set_handler (G_LOG_DOMAIN, @@ -965,8 +998,12 @@ int main(int argc, char ** argv) return 0; } else if (strcmp(argv[i],"-d")==0) { daemon_mode = FALSE; + } else if (strcmp(argv[i],"--force-window-manager")==0) { + force_window_manager = TRUE; + } else if (strcmp(argv[i],"--force-decorator")==0) { + force_decorator = TRUE; } else { - usage(argv[0]); + usage(argv[0]); return 1; } } @@ -983,71 +1020,61 @@ int main(int argc, char ** argv) return 3; } + d = XOpenDisplay(NULL); + if ((running_window = Window_With_Name(d, + DefaultRootWindow(d), + // GDK_WINDOW_XID( + // gdk_get_default_root_window() + // ), + "Beryl Manager"))) + // "Event Tester"))) + { + XEvent clientEvent; + gboolean missed = FALSE; + + PopupRunning = XInternAtom(d,"beryl-manager-Popup",0); + + clientEvent.xclient.type = ClientMessage; + clientEvent.xclient.window = running_window; + clientEvent.xclient.message_type = PopupRunning; + clientEvent.xclient.format = 32; + clientEvent.xclient.display = d; + clientEvent.xclient.data.l[0] = 0; + clientEvent.xclient.data.l[1] = 0; + clientEvent.xclient.data.l[2] = 0; + clientEvent.xclient.data.l[3] = 0; + clientEvent.xclient.data.l[4] = 0; + // gdk_error_trap_push (); + missed = XSendEvent(d,running_window, + False, + NoEventMask, + &clientEvent); + XSync (d, False); + // gdk_error_trap_pop (); + return 0; + } + XCloseDisplay(d); + + gtk_init(&argc,&argv); d = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); buffer = g_strdup(DisplayString(gdk_x11_display_get_xdisplay(gdk_display_get_default()))); if (buffer) { - gint num; - gchar *p=buffer; - displayname = g_strdup(buffer); - - if (g_strrstr(p,":")) { - p=g_strrstr(p,":"); - p++; - } - num = atoi(p); + displayname = display_part(buffer); g_free(buffer); - buffer = g_strdup_printf("%d",num); - } else { - buffer=strdup("-"); } - - pidfile = g_strconcat(g_get_home_dir(),"/.beryl-manager.",buffer,".pid", NULL); - g_free(buffer); - - - //Already running? Get the pid out of the file - if (g_file_get_contents(pidfile,&buffer,NULL,NULL)) { - GPid pid = atoi(buffer); - gchar * pret; - g_free(buffer); + if (!g_thread_supported()) g_thread_init(NULL); + gdk_threads_init (); + gdk_threads_enter (); + mutx=g_mutex_new(); - // Look for already live instances - if (pid && - g_spawn_command_line_sync("pidof beryl-manager", - &pret, - NULL,NULL,NULL)) { - g_strchomp(pret); - if (pret && *pret) { - gchar **pidlist = g_strsplit(pret," ",0); - i = 0; - while (pidlist[i]) { - if (pid == atoi(pidlist[i])) { - //correct process exists - if (kill(pid,SIGUSR1)==0) { - //signal delivered - return 0; - } - } - i++; - } - g_strfreev(pidlist); - } - if (pret) - g_free(pret); - } - } - buffer = g_strdup_printf("%d\n",getpid()); - g_file_set_contents(pidfile, buffer, -1, NULL); - g_free(buffer); // Check for the windows manager - wmAtom = XInternAtom(d,"WM_S0",1); - - if (!g_thread_supported()) g_thread_init(NULL); - mutx=g_mutex_new(); + buffer = g_strconcat("WM_S",displayname,NULL); + wmAtom = XInternAtom(d,buffer,0); + g_free (buffer); detect_xgl(); if (!XGL) detect_nvidia(); @@ -1100,13 +1127,62 @@ int main(int argc, char ** argv) if (DM==-1) manager_error("No Display Manager Found!"); save_settings(); - - if (!is_wm_running(WM)) + + if (!force_window_manager) { + gint found = False; + for (i=0;i<=numWM && !found;i++) + if (is_wm_running(i)) + found = True; + if (!found) + launchWM(); + } else if (!is_wm_running(WM)) { launchWM(); + } signal (SIGUSR1, signalHandler); gtk_main(); + gdk_threads_leave (); - g_unlink(pidfile); return 0; } + + + +/* - - - - - - - - - + +* [These functions are from the file "dsimple.c" used with xwininfo.] +* +* Written by Mark Lillibridge. Last updated 7/1/87 +* +* +* Window_With_Name: routine to locate a window with a given name on a display. +* If no window with the given name is found, 0 is returned. +* If more than one window has the given name, the first +* one found will be returned. Only top and its subwindows +* are looked at. Normally, top should be the Root Window. +*/ +static Window +Window_With_Name (Display * dpy, Window top, char *name) +{ + Window *children, dummy; + unsigned int nchildren; + unsigned i; + Window w = 0; + char *window_name; + + if (XFetchName (dpy, top, &window_name) && !strcmp (window_name, name)) + return (top); + + if (!XQueryTree (dpy, top, &dummy, &dummy, &children, &nchildren)) + return (0); + + for (i = 0; i < nchildren; i++) + { + w = Window_With_Name (dpy, children[i], name); + if (w) + break; + } + if (children) + XFree ((char *) children); + return (w); +} |