split out functionality for talking to gnome-screensaver into GnomeScreensaver class
This commit is contained in:
parent
e0fe3be5b2
commit
993d09cccb
158
GnomeScreensaver.cc
Normal file
158
GnomeScreensaver.cc
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
|
||||||
|
#include "GnomeScreensaver.h"
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
expose (GtkWidget *da, GdkEventExpose *event, GnomeScreensaver *gs)
|
||||||
|
{
|
||||||
|
return gs->exposeCB(da, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
configure (GtkWidget *da, GdkEventConfigure *event, GnomeScreensaver *gs)
|
||||||
|
{
|
||||||
|
return gs->configureCB(da, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
update (void *gs)
|
||||||
|
{
|
||||||
|
return ((GnomeScreensaver *)gs)->updateCB();
|
||||||
|
}
|
||||||
|
|
||||||
|
GnomeScreensaver::GnomeScreensaver(int *argc, char ***argv,
|
||||||
|
bool (*configure_callback)(GnomeScreensaver &, int, int),
|
||||||
|
bool (*expose_callback)(GnomeScreensaver &),
|
||||||
|
bool (*update_callback)(GnomeScreensaver &),
|
||||||
|
int32_t interval_msec)
|
||||||
|
: m_configure_callback(configure_callback),
|
||||||
|
m_expose_callback(expose_callback),
|
||||||
|
m_update_callback(update_callback)
|
||||||
|
{
|
||||||
|
gchar *geometry = NULL;
|
||||||
|
GOptionEntry options[] = {
|
||||||
|
{"geometry", 0, 0, G_OPTION_ARG_STRING, &geometry,
|
||||||
|
N_("The initial size and position of window"),
|
||||||
|
N_("WIDTHxHEIGHT+X+Y")},
|
||||||
|
{NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
GtkWidget *window;
|
||||||
|
GdkGLConfig *glconfig;
|
||||||
|
GtkStateType state;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
gtk_init_with_args (argc, argv,
|
||||||
|
_(""),
|
||||||
|
NULL, NULL, &error);
|
||||||
|
gtk_gl_init(argc, argv);
|
||||||
|
|
||||||
|
if (error != NULL)
|
||||||
|
{
|
||||||
|
g_printerr (_("%s. See --help for usage information.\n"),
|
||||||
|
_(error->message));
|
||||||
|
g_error_free (error);
|
||||||
|
}
|
||||||
|
|
||||||
|
window = gs_theme_window_new ();
|
||||||
|
|
||||||
|
g_signal_connect (G_OBJECT (window), "delete-event",
|
||||||
|
G_CALLBACK (gtk_main_quit), NULL);
|
||||||
|
|
||||||
|
m_drawing_area = gtk_drawing_area_new ();
|
||||||
|
|
||||||
|
glconfig = gdk_gl_config_new_by_mode( (GdkGLConfigMode)
|
||||||
|
( GDK_GL_MODE_RGB |
|
||||||
|
GDK_GL_MODE_DEPTH |
|
||||||
|
GDK_GL_MODE_DOUBLE ) );
|
||||||
|
|
||||||
|
if (!glconfig)
|
||||||
|
{
|
||||||
|
g_assert_not_reached();
|
||||||
|
}
|
||||||
|
if (!gtk_widget_set_gl_capability(m_drawing_area, glconfig, NULL, TRUE,
|
||||||
|
GDK_GL_RGBA_TYPE))
|
||||||
|
{
|
||||||
|
g_assert_not_reached();
|
||||||
|
}
|
||||||
|
|
||||||
|
g_signal_connect(m_drawing_area, "configure-event",
|
||||||
|
G_CALLBACK(configure), this);
|
||||||
|
g_signal_connect(m_drawing_area, "expose-event",
|
||||||
|
G_CALLBACK(expose), this);
|
||||||
|
|
||||||
|
gtk_widget_show (m_drawing_area);
|
||||||
|
gtk_container_add (GTK_CONTAINER (window), m_drawing_area);
|
||||||
|
|
||||||
|
if ((geometry == NULL)
|
||||||
|
|| !gtk_window_parse_geometry (GTK_WINDOW (window), geometry))
|
||||||
|
{
|
||||||
|
gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_widget_show (window);
|
||||||
|
|
||||||
|
gtk_timeout_add(interval_msec, update, this);
|
||||||
|
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
m_start_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t GnomeScreensaver::getTicks()
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
uint64_t msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||||
|
return msec - m_start_msec;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean GnomeScreensaver::exposeCB(GtkWidget *da, GdkEventExpose *event)
|
||||||
|
{
|
||||||
|
GdkGLContext *glcontext = gtk_widget_get_gl_context(da);
|
||||||
|
GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(da);
|
||||||
|
|
||||||
|
if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
|
||||||
|
{
|
||||||
|
g_assert_not_reached();
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean rc = m_expose_callback(*this);
|
||||||
|
|
||||||
|
if (gdk_gl_drawable_is_double_buffered(gldrawable))
|
||||||
|
gdk_gl_drawable_swap_buffers(gldrawable);
|
||||||
|
else
|
||||||
|
glFlush();
|
||||||
|
|
||||||
|
gdk_gl_drawable_gl_end(gldrawable);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean GnomeScreensaver::configureCB(GtkWidget *da, GdkEventConfigure *event)
|
||||||
|
{
|
||||||
|
GdkGLContext *glcontext = gtk_widget_get_gl_context(da);
|
||||||
|
GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(da);
|
||||||
|
|
||||||
|
if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
|
||||||
|
{
|
||||||
|
g_assert_not_reached();
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean rc = m_configure_callback(*this,
|
||||||
|
da->allocation.width, da->allocation.height);
|
||||||
|
|
||||||
|
gdk_gl_drawable_gl_end(gldrawable);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean GnomeScreensaver::updateCB()
|
||||||
|
{
|
||||||
|
gboolean rc = m_update_callback(*this);
|
||||||
|
if (rc)
|
||||||
|
{
|
||||||
|
gtk_widget_queue_draw(m_drawing_area);
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
46
GnomeScreensaver.h
Normal file
46
GnomeScreensaver.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
#ifndef GNOMESCREENSAVER_H
|
||||||
|
#define GNOMESCREENSAVER_H
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <glib/gi18n.h>
|
||||||
|
|
||||||
|
#include <gdk/gdk.h>
|
||||||
|
#include <gdk/gdkx.h>
|
||||||
|
#include <gdk/gdkgl.h>
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <gtk/gtkgl.h>
|
||||||
|
|
||||||
|
#include <GL/gl.h>
|
||||||
|
#include <GL/glu.h>
|
||||||
|
|
||||||
|
#include "gs-theme-window.h"
|
||||||
|
|
||||||
|
class GnomeScreensaver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GnomeScreensaver(int *argc, char ***argv,
|
||||||
|
bool (*configure_callback)(GnomeScreensaver &, int, int),
|
||||||
|
bool (*expose_callback)(GnomeScreensaver &),
|
||||||
|
bool (*update_callback)(GnomeScreensaver &),
|
||||||
|
int32_t interval_msec);
|
||||||
|
uint32_t getTicks();
|
||||||
|
void mainloop() { gtk_main(); }
|
||||||
|
gboolean configureCB(GtkWidget *da, GdkEventConfigure *event);
|
||||||
|
gboolean exposeCB(GtkWidget *da, GdkEventExpose *event);
|
||||||
|
gboolean updateCB();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
GtkWidget *m_drawing_area;
|
||||||
|
uint64_t m_start_msec;
|
||||||
|
bool (*m_configure_callback)(GnomeScreensaver &, int, int);
|
||||||
|
bool (*m_expose_callback)(GnomeScreensaver &);
|
||||||
|
bool (*m_update_callback)(GnomeScreensaver &);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* GNOMESCREENSAVER_H */
|
||||||
|
|
183
dwss.cc
183
dwss.cc
@ -1,28 +1,3 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2005 Ray Strode <rstrode@redhat.com>,
|
|
||||||
* Matthias Clasen <mclasen@redhat.com>,
|
|
||||||
* Søren Sandmann <sandmann@redhat.com>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
||||||
* 02111-1307, USA.
|
|
||||||
*
|
|
||||||
* Originally written by: Ray Strode <rstrode@redhat.com>
|
|
||||||
*
|
|
||||||
* Later contributions by: Matthias Clasen <mclasen@redhat.com>
|
|
||||||
* Søren Sandmann <sandmann@redhat.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -30,56 +5,17 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include <glib.h>
|
|
||||||
#include <glib/gi18n.h>
|
|
||||||
|
|
||||||
#include <gdk/gdk.h>
|
|
||||||
#include <gdk/gdkx.h>
|
|
||||||
#include <gdk/gdkgl.h>
|
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
|
||||||
#include <gtk/gtkgl.h>
|
|
||||||
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
|
|
||||||
#include "gs-theme-window.h"
|
#include "GnomeScreensaver.h"
|
||||||
|
|
||||||
static gchar *geometry = NULL;
|
static bool expose (GnomeScreensaver & gs)
|
||||||
static GtkWidget *drawing_area;
|
|
||||||
|
|
||||||
static GOptionEntry options[] = {
|
|
||||||
{"geometry", 0, 0, G_OPTION_ARG_STRING, &geometry,
|
|
||||||
N_("The initial size and position of window"),
|
|
||||||
N_("WIDTHxHEIGHT+X+Y")},
|
|
||||||
{NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
static uint64_t start_msec;
|
|
||||||
|
|
||||||
static uint32_t getElapsedTime()
|
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
uint64_t msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
|
||||||
return msec - start_msec;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
expose (GtkWidget *da, GdkEventExpose *event, gpointer user_data)
|
|
||||||
{
|
|
||||||
GdkGLContext *glcontext = gtk_widget_get_gl_context(da);
|
|
||||||
GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(da);
|
|
||||||
|
|
||||||
if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
|
|
||||||
{
|
|
||||||
g_assert_not_reached();
|
|
||||||
}
|
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glRotatef(getElapsedTime()/1000.0*360.0, 0, 0, 1);
|
glRotatef(gs.getTicks()/1000.0*360.0, 0, 0, 1);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glColor3f(1, 0.6, 0);
|
glColor3f(1, 0.6, 0);
|
||||||
glNormal3f(0, 0, 1);
|
glNormal3f(0, 0, 1);
|
||||||
@ -90,35 +26,16 @@ expose (GtkWidget *da, GdkEventExpose *event, gpointer user_data)
|
|||||||
glEnd();
|
glEnd();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
if (gdk_gl_drawable_is_double_buffered(gldrawable))
|
return true;
|
||||||
gdk_gl_drawable_swap_buffers(gldrawable);
|
|
||||||
else
|
|
||||||
glFlush();
|
|
||||||
|
|
||||||
gdk_gl_drawable_gl_end(gldrawable);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static bool configure (GnomeScreensaver & gs, int width, int height)
|
||||||
configure (GtkWidget *da, GdkEventConfigure *event, gpointer user_data)
|
|
||||||
{
|
{
|
||||||
GdkGLContext *glcontext = gtk_widget_get_gl_context(da);
|
glViewport(0, 0, width, height);
|
||||||
GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(da);
|
|
||||||
|
|
||||||
if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
|
|
||||||
{
|
|
||||||
g_assert_not_reached();
|
|
||||||
}
|
|
||||||
|
|
||||||
glViewport(0, 0, da->allocation.width, da->allocation.height);
|
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective(60.0,
|
gluPerspective(60.0, (double)width / (double)height, 0.001, 1000.0);
|
||||||
(double)da->allocation.width / (double)da->allocation.height,
|
|
||||||
0.001,
|
|
||||||
1000.0);
|
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
@ -126,91 +43,19 @@ configure (GtkWidget *da, GdkEventConfigure *event, gpointer user_data)
|
|||||||
|
|
||||||
glShadeModel(GL_SMOOTH);
|
glShadeModel(GL_SMOOTH);
|
||||||
|
|
||||||
gdk_gl_drawable_gl_end(gldrawable);
|
return true;
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static bool update (GnomeScreensaver & gs)
|
||||||
update (void *user_data)
|
|
||||||
{
|
{
|
||||||
gtk_widget_queue_draw(drawing_area);
|
return true;
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int main (int argc, char *argv[])
|
||||||
main (int argc,
|
|
||||||
char *argv[])
|
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
GnomeScreensaver gs(&argc, &argv, configure, expose, update, 12);
|
||||||
GdkGLConfig *glconfig;
|
|
||||||
|
|
||||||
GtkStateType state;
|
gs.mainloop();
|
||||||
|
|
||||||
GError *error;
|
return 0;
|
||||||
|
|
||||||
error = NULL;
|
|
||||||
|
|
||||||
gtk_init_with_args (&argc, &argv,
|
|
||||||
_("DornerWorks ScreenSaver"),
|
|
||||||
NULL, NULL, &error);
|
|
||||||
gtk_gl_init(&argc, &argv);
|
|
||||||
|
|
||||||
|
|
||||||
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 ();
|
|
||||||
|
|
||||||
glconfig = gdk_gl_config_new_by_mode( (GdkGLConfigMode)
|
|
||||||
( GDK_GL_MODE_RGB |
|
|
||||||
GDK_GL_MODE_DEPTH |
|
|
||||||
GDK_GL_MODE_DOUBLE ) );
|
|
||||||
|
|
||||||
if (!glconfig)
|
|
||||||
{
|
|
||||||
g_assert_not_reached();
|
|
||||||
}
|
|
||||||
if (!gtk_widget_set_gl_capability(drawing_area, glconfig, NULL, TRUE,
|
|
||||||
GDK_GL_RGBA_TYPE))
|
|
||||||
{
|
|
||||||
g_assert_not_reached();
|
|
||||||
}
|
|
||||||
|
|
||||||
g_signal_connect(drawing_area, "configure-event",
|
|
||||||
G_CALLBACK(configure), NULL);
|
|
||||||
g_signal_connect(drawing_area, "expose-event",
|
|
||||||
G_CALLBACK(expose), NULL);
|
|
||||||
|
|
||||||
gtk_widget_show (drawing_area);
|
|
||||||
gtk_container_add (GTK_CONTAINER (window), drawing_area);
|
|
||||||
|
|
||||||
if ((geometry == NULL)
|
|
||||||
|| !gtk_window_parse_geometry (GTK_WINDOW (window), geometry))
|
|
||||||
{
|
|
||||||
gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_widget_show (window);
|
|
||||||
|
|
||||||
gtk_timeout_add(12, update, NULL);
|
|
||||||
|
|
||||||
struct timeval tv;
|
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
start_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
|
||||||
|
|
||||||
gtk_main ();
|
|
||||||
|
|
||||||
return EX_OK;
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user