I am writing a small proprietary procedure to notify another process that the user has changed the screen resolution. I tried using gtk, but it is unstable for non-shared window managers and often crashes. I am learning xlib and have an example of work that notifies me when the generated size of the X Window changes, but I cannot figure out how to get a notification that the screen resolution has changed. Any help would be greatly appreciated. I include my xlib test code and gtk + test code, which, as indicated, crashes badly when using non-component window managers.
Here is my test code using xlib
Display * display; int screen; Window root, window; display = XOpenDisplay (NULL); if (!display){ syslog(LOG_INFO, "Could not open display.\n"); } screen = DefaultScreen(display); root = RootWindow(display, screen); window = XCreateSimpleWindow (display, root, 0, 0, 300, 300,
Test code using GTK +
GtkWidget *window; GdkScreen *screen; screen = gdk_screen_get_default(); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); syslog(LOG_INFO, "NATIVESUPPORT: startDisplayChangedEventThread(): screen and window objects created.\n"); if (!screen){ syslog(LOG_INFO, "NATIVESUPPORT: screen is null."); } if (!window){ syslog(LOG_INFO, "NATIVESUPPORT: window is null."); } g_signal_connect(screen, "size-changed", G_CALLBACK(resize_cb), (gpointer)window); g_signal_connect(screen, "monitors-changed", G_CALLBACK(resize_cb), (gpointer)window); syslog(LOG_INFO, "NATIVESUPPORT: startDisplayChangedEventThread(): call back created.\n"); syslog(LOG_INFO, "NATIVESUPPORT: startDisplayChangedEventThread(): starting main.\n"); gtk_main();
source share