A Slideshow Screensaver Using C, Gtk+ & Gdk

Yes, I know I am re-inventing the wheel, but I thought this would be an interesting exercise for teaching myself C under Ubuntu Linux and Gnome.

I want a black background against which the .jpg images will be shown. I also want the screensaver to respond to keyboard events so that it can do various things depending on which key is pressed.

The only way I have discovered of getting a completely black background is with a GTK_WINDOW_POPUP, which is displayed independently of the window manager and so hides the Gnome top & bottom panels.

I then use a GTK_WINDOW_TOPLEVEL with gtk_window_set_decorated = FALSE to display the images without borders.

This second window sucessfully receives keyboard events ... but is unfortunately invisible, presumably because the window manager displays it under the black GTK_WINDOW_POPUP. I have tried various things to get the desired result, but without success.

Can anyone suggest a method of achieving my aim? I would prefer to work at the GTK / GDK levels rather than at the Xwindow level.

Code follows:

/* Declare widgets etc.
-----------------------*/

/* black background window */
GtkWindow *window_bg;
GdkPixbuf *pixbuf_bg;
GtkWidget *picture_bg;

/* image display window */
GtkWindow *window;
GdkPixbuf *pixbuf;
GtkWidget *picture;


int main(int argc, char **argv)
{
/* Initialise GTK+ */
gtk_init(&argc, &argv);

/* ***** Create & display black background *******/
window_bg = GTK_WINDOW(gtk_window_new(GTK_WINDOW_POPUP));
pixbuf_bg = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
FALSE, 8, 1280, 1024); /* default black pixbuf */

picture_bg=gtk_image_new_from_pixbuf(pixbuf_bg);
gtk_container_add(GTK_CONTAINER(window_bg), GTK_WIDGET(picture_bg));
gtk_widget_show_all(GTK_WIDGET(window_bg));

/* ***** Create photo display ******/
window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
pixbuf = gdk_pixbuf_new_from_file_at_scale("test.jpg", 1280, 1024, TRUE, NULL);
picture=gtk_image_new_from_pixbuf(pixbuf);

/* signal handlers would be here */

/* pack the image into the window & display */
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(picture));
gtk_widget_show_all(GTK_WIDGET(window));

/* Set window to have no border etc. */
gtk_window_set_decorated(window, FALSE);

/* Start main event loop */
gtk_main();

return 0;
}

Thanks,

Kevin

This reply is probably too late for Kevin. But when I was trying to solve the same problem, I kept finding this forum post in Google. Later, I found the answer. So my hope is that by putting the answer here, it'll be easier to find for me or others in the future who are searching on "gtk" and "screensaver".

The short answer is gtk_window_fullscreen(). I tried it in Windows XP (actually, in gtkmm, the Gdk::window::fullscreen() method). Worked perfectly.

The documentation doesn't say that it avoids window decorations (title bar etc.), but it did for me. Didn't show the taskbar either. Looks like I have total screen control, which is what I want for a screensaver.

Apparently it works in Linux too, at least in KDE.

HTH,
Lars