diff options
-rw-r--r-- | ulock.c | 44 |
1 files changed, 42 insertions, 2 deletions
@@ -40,6 +40,10 @@ static char *logoutCommand = NULL; static int logoutTime = 0; +static Atom atom; +static Window selection; + + static gboolean do_grab_devices(gpointer user_data) { DEBUG("do_grab_devices"); @@ -181,7 +185,7 @@ static void try_unlock(void) { gtk_label_set_label(GTK_LABEL(messageLabel), ""); pthread_t thread; - pthread_create(&thread, NULL, try_unlock_thread, strdup((char*)gtk_entry_get_text(GTK_ENTRY(promptEntry)))); + pthread_create(&thread, NULL, try_unlock_thread, strdup(gtk_entry_get_text(GTK_ENTRY(promptEntry)))); pthread_detach(thread); } @@ -213,6 +217,11 @@ static GdkFilterReturn xevent_filter(GdkXEvent *xevent, GdkEvent *event, gpointe gtk_window_present(GTK_WINDOW(window)); break; + case DestroyNotify: + if (ev->xdestroywindow.window == selection) + gtk_main_quit(); + break; + default: break; } @@ -220,10 +229,42 @@ static GdkFilterReturn xevent_filter(GdkXEvent *xevent, GdkEvent *event, gpointe return GDK_FILTER_CONTINUE; } +static void wait_for_selection(void) { + DEBUG("wait_for_selection"); + + GdkDisplay *display = gdk_display_get_default(); + Display *xdisplay = gdk_x11_display_get_xdisplay(display); + gdk_x11_display_error_trap_push(display); + + XSelectInput(xdisplay, selection, StructureNotifyMask); + + if (gdk_x11_display_error_trap_pop(display)) + return; + + gtk_main(); +} static void create_lock_window(void) { window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_widget_realize(window); + gdk_window_add_filter(NULL, (GdkFilterFunc)xevent_filter, NULL); + + atom = gdk_x11_get_xatom_by_name("ULOCK"); + + gdk_x11_grab_server(); + + selection = XGetSelectionOwner(gdk_x11_get_default_xdisplay(), atom); + if (selection == None) + XSetSelectionOwner(gdk_x11_get_default_xdisplay(), atom, gdk_x11_window_get_xid(gtk_widget_get_window(window)), CurrentTime); + + gdk_x11_ungrab_server(); + + if (selection != None) { + wait_for_selection(); + exit(0); + } + gtk_window_set_decorated(GTK_WINDOW(window), FALSE); gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), TRUE); gtk_window_set_skip_pager_hint(GTK_WINDOW(window), TRUE); @@ -262,7 +303,6 @@ static void create_lock_window(void) { g_signal_connect(window, "delete-event", G_CALLBACK(gtk_true), NULL); XSelectInput(gdk_x11_get_default_xdisplay(), gdk_x11_get_default_root_xwindow(), SubstructureNotifyMask); - gdk_window_add_filter(NULL, (GdkFilterFunc)xevent_filter, NULL); update_logout_time(); } |