日本語 English


How to make GNOME screensaver

Last modified: 2009/05/31

Theme: Make scalable screensaver skeleton that can run on GNOME.

First, extract gnome-screensaver source, copy gs-theme-window.c and gs-theme-window.h in savers/ directory.

Next, create empty config.h (touch config.h).

Screensaver body:

gs-base.c
#include <sysexits.h>
#include "gs-theme-window.h"

GOptionEntry options[] = { {NULL} };

static void configure_event (GtkWidget *widget, GdkEventConfigure *event, gpointer data)
{
}

static void expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
}

int main (int argc, char **argv)
{
  GtkWidget *window;
  GtkWidget *drawing_area;
  GError *error = NULL;

  gtk_set_locale ();

  gtk_init_with_args (&argc, &argv,
                      "",
                      options,
                      "gnome-screensaver",
                      &error);

  if (error != NULL)
    {
      g_printerr ("%s. See --help for usage information.\n",
                  error->message);
      g_error_free (error);
      return EX_SOFTWARE;
    }

  window = gs_theme_window_new ();
  g_signal_connect (G_OBJECT (window), "delete-event",
                    G_CALLBACK (gtk_main_quit), NULL);

  drawing_area = gtk_drawing_area_new ();
  gtk_signal_connect (GTK_OBJECT (drawing_area), "configure_event",
                      GTK_SIGNAL_FUNC (configure_event), NULL);
  gtk_signal_connect (GTK_OBJECT (drawing_area), "expose_event",
                      GTK_SIGNAL_FUNC (expose_event), NULL);

  gtk_widget_show (drawing_area);
  gtk_container_add (GTK_CONTAINER (window), drawing_area);

  gtk_widget_show (window);

  gtk_main ();

  return EX_OK;
}

Obviously, this is a typical GTK+ application but using window = gs_theme_window_new (); instead of window = gtk_window_new (GTK_WINDOW_TOPLEVEL);.

skeleton.desktop:

skeleton.desktop
[Desktop Entry]
Encoding=UTF-8
Name=Skeleton
Comment=Skeleton screen saver
Exec=skeleton
TryExec=skeleton
StartupNotify=false
Terminal=false
Type=Application
Categories=GNOME;Screensaver;
OnlyShowIn=GNOME;

Makefile (for GTK+ 2.0):

Makefile
CC = gcc
PKG_CONFIG = pkg-config
GTK_METADATA = gtk+-2.0
INSTALL = install
GS_LIBEXEC_DIR = `${PKG_CONFIG} --variable=privlibexecdir gnome-screensaver`
GS_DESKTOP_DIR = `${PKG_CONFIG} --variable=themesdir gnome-screensaver`

SOURCES = gs-theme-window.c gs-base.c
TARGET = skeleton
DESKTOP = ${TARGET}.desktop

OBJECTS = $(SOURCES:.c=.o)
CFLAGS = `${PKG_CONFIG} ${GTK_METADATA} --cflags` -Wall
LIBS = `${PKG_CONFIG} ${GTK_METADATA} --libs`

$(TARGET): $(OBJECTS)
<--TAB-->$(CC) $(CFLAGS) -o $@ $(OBJECTS) $(LIBS)
.c.o:
<--TAB-->$(CC) $(CFLAGS) -c $< -o $@
clean:
<--TAB-->rm -f $(OBJECTS) $(TARGET) core* *.o *~
install:
<--TAB-->${INSTALL} -s ${TARGET} ${GS_LIBEXEC_DIR}
<--TAB-->${INSTALL} -m 644 ${DESKTOP} ${GS_DESKTOP_DIR}

Finally, you can:
make
su
make install

That's all. Play the NAFF, UGLY, GREAT screensaver!

Now, you can implement configure_event, expose_event and timer.

Happy hacking!

Appendix

Clock screensaver for MATE


Valid HTML 4.01 Strict Valid CSS 2.1