Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * intercept-wm-close.c - WM_DELETE_WINDOW experiment, part 2
- * Copyright (C) 2009 Michael B. Trausch <[email protected]>
- *
- * Determines whether or not we can intercept an WM_DELETE_WINDOW
- * event, such that we would be able to direct a window back to the
- * system tray instead of actually delete it.
- */
- // Standard UNIX includes
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- // GNU readline
- #include <readline/readline.h>
- #include <readline/history.h>
- // Xlib
- #include <X11/Xlib.h>
- #include <X11/Xatom.h>
- // glib and gdk
- #include <glib.h>
- #include <gdk/gdk.h>
- #define RETVAL_SUCCESS 0
- #define RETVAL_NO_X11_DISPLAY 1
- #define RETVAL_GDK_FAILED 2
- GdkFilterReturn
- cb(GdkXEvent *xev, GdkEvent *ev, gpointer data) {
- XEvent *real_xev = (XEvent *)xev;
- if(real_xev->type == ClientMessage) {
- fprintf(stdout, "Got an event.\n");
- fprintf(stdout, " ... for window %ld.\n", real_xev->xclient.window);
- }
- return(GDK_FILTER_CONTINUE);
- }
- int
- main(int argc, char *argv[]) {
- GdkDisplay *gd = NULL;
- GdkAtom wm_delete_window;
- int found = 0;
- Window w = (Window)0;
- char *line = NULL;
- gboolean gdkis = FALSE;
- GMainLoop *gml = NULL;
- gml = g_main_loop_new(NULL, FALSE);
- gdkis = gdk_init_check(&argc, &argv);
- if(gdkis == FALSE) {
- fprintf(stderr, "Cannot open display, exiting.\n");
- exit(RETVAL_NO_X11_DISPLAY);
- }
- gd = gdk_display_open(NULL);
- wm_delete_window = gdk_atom_intern("WM_DELETE_WINDOW", FALSE);
- while(!found) {
- try_again:
- line = readline("Enter the X11 ID to intercept WM_DELETE_WINDOW for: ");
- if(line == NULL) {
- fprintf(stderr, "Error: invalid window ID\n");
- goto try_again;
- }
- w = (Window)atol(line);
- GdkWindow *gw = gdk_window_foreign_new((GdkNativeWindow)w);
- if(gw != NULL) {
- found = 1;
- } else {
- fprintf(stderr, "Error: window ID %ld did not return a result.\n", w);
- }
- }
- fprintf(stdout, "Broke out of the loop, found the window.\n");
- gdk_display_add_client_message_filter(gd, wm_delete_window, cb, NULL);
- gdk_window_add_filter(gw, cb, NULL);
- g_main_loop_run(gml);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement