2005-03-22 14:53:51 +00:00
|
|
|
#include "cltr.h"
|
|
|
|
|
2005-03-23 17:33:37 +00:00
|
|
|
#include <X11/keysym.h>
|
2005-03-22 14:53:51 +00:00
|
|
|
|
2005-03-23 17:33:37 +00:00
|
|
|
/* temp temp temp */
|
2005-03-22 14:53:51 +00:00
|
|
|
|
2005-03-23 17:33:37 +00:00
|
|
|
float Zoom = 1.0;
|
|
|
|
ClutterPhotoGrid *Grid = NULL;
|
2005-03-22 17:25:52 +00:00
|
|
|
|
2005-03-23 17:33:37 +00:00
|
|
|
/* ************* */
|
2005-03-22 17:25:52 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
x_event_prepare (GSource *source,
|
|
|
|
gint *timeout)
|
|
|
|
{
|
|
|
|
Display *display = ((CltrXEventSource*)source)->display;
|
|
|
|
|
|
|
|
*timeout = -1;
|
|
|
|
|
|
|
|
return XPending (display);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
x_event_check (GSource *source)
|
|
|
|
{
|
|
|
|
CltrXEventSource *display_source = (CltrXEventSource*)source;
|
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
if (display_source->event_poll_fd.revents & G_IO_IN)
|
|
|
|
retval = XPending (display_source->display);
|
|
|
|
else
|
|
|
|
retval = FALSE;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
x_event_dispatch (GSource *source,
|
|
|
|
GSourceFunc callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
Display *display = ((CltrXEventSource*)source)->display;
|
|
|
|
CltrXEventFunc event_func = (CltrXEventFunc) callback;
|
|
|
|
|
|
|
|
XEvent xev;
|
|
|
|
|
|
|
|
if (XPending (display))
|
|
|
|
{
|
|
|
|
XNextEvent (display, &xev);
|
|
|
|
|
|
|
|
if (event_func)
|
|
|
|
(*event_func) (&xev, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GSourceFuncs x_event_funcs = {
|
|
|
|
x_event_prepare,
|
|
|
|
x_event_check,
|
|
|
|
x_event_dispatch,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2005-03-27 20:12:19 +00:00
|
|
|
void
|
|
|
|
cltr_dispatch_expose(XExposeEvent *xexpev)
|
|
|
|
{
|
|
|
|
cltr_photo_grid_redraw(Grid);
|
|
|
|
}
|
|
|
|
|
2005-03-23 17:33:37 +00:00
|
|
|
void
|
|
|
|
cltr_dispatch_keypress(XKeyEvent *xkeyev)
|
|
|
|
{
|
|
|
|
KeySym kc;
|
|
|
|
|
|
|
|
kc = XKeycodeToKeysym(xkeyev->display, xkeyev->keycode, 0);
|
|
|
|
|
|
|
|
switch (kc)
|
|
|
|
{
|
|
|
|
case XK_Left:
|
|
|
|
case XK_KP_Left:
|
|
|
|
cltr_photo_grid_navigate(Grid, CLTR_WEST);
|
|
|
|
break;
|
|
|
|
case XK_Up:
|
|
|
|
case XK_KP_Up:
|
|
|
|
cltr_photo_grid_navigate(Grid, CLTR_NORTH);
|
|
|
|
break;
|
|
|
|
case XK_Right:
|
|
|
|
case XK_KP_Right:
|
|
|
|
cltr_photo_grid_navigate(Grid, CLTR_EAST);
|
|
|
|
break;
|
|
|
|
case XK_Down:
|
|
|
|
case XK_KP_Down:
|
|
|
|
cltr_photo_grid_navigate(Grid, CLTR_SOUTH);
|
|
|
|
break;
|
|
|
|
case XK_Return:
|
|
|
|
cltr_photo_grid_activate_cell(Grid);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CLTR_DBG("unhandled keysym");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-22 17:25:52 +00:00
|
|
|
static void
|
|
|
|
cltr_dispatch_x_event (XEvent *xevent,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2005-03-23 17:33:37 +00:00
|
|
|
/* Should actually forward on to focussed widget */
|
2005-03-22 17:25:52 +00:00
|
|
|
|
|
|
|
switch (xevent->type)
|
|
|
|
{
|
|
|
|
case MapNotify:
|
|
|
|
CLTR_DBG("Map Notify Event");
|
|
|
|
break;
|
|
|
|
case Expose:
|
2005-03-27 20:12:19 +00:00
|
|
|
CLTR_DBG("Expose"); /* TODO COMPRESS */
|
|
|
|
cltr_dispatch_expose(&xevent->xexpose);
|
2005-03-22 17:25:52 +00:00
|
|
|
break;
|
2005-03-23 17:33:37 +00:00
|
|
|
case KeyPress:
|
|
|
|
CLTR_DBG("KeyPress");
|
|
|
|
cltr_dispatch_keypress(&xevent->xkey);
|
|
|
|
break;
|
2005-03-22 17:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-22 14:53:51 +00:00
|
|
|
int
|
|
|
|
cltr_init(int *argc, char ***argv)
|
|
|
|
{
|
|
|
|
int gl_attributes[] =
|
|
|
|
{
|
|
|
|
GLX_RGBA,
|
|
|
|
GLX_DOUBLEBUFFER,
|
|
|
|
GLX_RED_SIZE, 1,
|
|
|
|
GLX_GREEN_SIZE, 1,
|
|
|
|
GLX_BLUE_SIZE, 1,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
XVisualInfo *vinfo;
|
|
|
|
|
2005-03-22 17:25:52 +00:00
|
|
|
GMainContext *gmain_context;
|
|
|
|
int connection_number;
|
|
|
|
GSource *source;
|
|
|
|
CltrXEventSource *display_source;
|
|
|
|
|
|
|
|
g_thread_init (NULL);
|
2005-03-27 20:12:19 +00:00
|
|
|
// XInitThreads ();
|
2005-03-22 17:25:52 +00:00
|
|
|
|
2005-03-22 14:53:51 +00:00
|
|
|
if ((CltrCntx.xdpy = XOpenDisplay(getenv("DISPLAY"))) == NULL)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CltrCntx.xscreen = DefaultScreen(CltrCntx.xdpy);
|
|
|
|
CltrCntx.xwin_root = RootWindow(CltrCntx.xdpy, CltrCntx.xscreen);
|
|
|
|
|
|
|
|
if ((vinfo = glXChooseVisual(CltrCntx.xdpy,
|
|
|
|
CltrCntx.xscreen,
|
|
|
|
gl_attributes)) == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unable to find visual\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CltrCntx.gl_context = glXCreateContext(CltrCntx.xdpy, vinfo, 0, True);
|
|
|
|
|
2005-03-22 17:25:52 +00:00
|
|
|
/* g_main loop stuff */
|
|
|
|
|
|
|
|
gmain_context = g_main_context_default ();
|
|
|
|
|
|
|
|
g_main_context_ref (gmain_context);
|
|
|
|
|
|
|
|
connection_number = ConnectionNumber (CltrCntx.xdpy);
|
|
|
|
|
|
|
|
source = g_source_new ((GSourceFuncs *)&x_event_funcs,
|
|
|
|
sizeof (CltrXEventSource));
|
|
|
|
|
|
|
|
display_source = (CltrXEventSource *)source;
|
|
|
|
|
|
|
|
display_source->event_poll_fd.fd = connection_number;
|
|
|
|
display_source->event_poll_fd.events = G_IO_IN;
|
|
|
|
display_source->display = CltrCntx.xdpy;
|
|
|
|
|
|
|
|
g_source_add_poll (source, &display_source->event_poll_fd);
|
|
|
|
g_source_set_can_recurse (source, TRUE);
|
|
|
|
|
|
|
|
g_source_set_callback (source,
|
|
|
|
(GSourceFunc) cltr_dispatch_x_event,
|
|
|
|
NULL /* no userdata */, NULL);
|
|
|
|
|
|
|
|
g_source_attach (source, gmain_context);
|
|
|
|
g_source_unref (source);
|
|
|
|
|
2005-03-22 14:53:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ClutterWindow*
|
|
|
|
cltr_window_new(int width, int height)
|
|
|
|
{
|
|
|
|
ClutterWindow *win;
|
|
|
|
|
|
|
|
win = util_malloc0(sizeof(ClutterWindow));
|
|
|
|
|
|
|
|
win->width = width;
|
|
|
|
win->height = height;
|
|
|
|
|
|
|
|
win->xwin = XCreateSimpleWindow(CltrCntx.xdpy,
|
|
|
|
CltrCntx.xwin_root,
|
|
|
|
0, 0,
|
|
|
|
width, height,
|
|
|
|
0, 0, WhitePixel(CltrCntx.xdpy,
|
|
|
|
CltrCntx.xscreen));
|
|
|
|
|
2005-03-22 17:25:52 +00:00
|
|
|
XSelectInput(CltrCntx.xdpy, win->xwin,
|
|
|
|
StructureNotifyMask|ExposureMask|
|
2005-03-23 17:33:37 +00:00
|
|
|
KeyPressMask|PropertyChangeMask);
|
2005-03-22 17:25:52 +00:00
|
|
|
|
2005-03-22 14:53:51 +00:00
|
|
|
glXMakeCurrent(CltrCntx.xdpy, win->xwin, CltrCntx.gl_context);
|
|
|
|
|
2005-03-25 17:22:10 +00:00
|
|
|
/* All likely better somewhere else */
|
|
|
|
|
|
|
|
/* view port */
|
2005-03-22 14:53:51 +00:00
|
|
|
glViewport (0, 0, width, height);
|
2005-03-25 17:22:10 +00:00
|
|
|
glMatrixMode (GL_PROJECTION);
|
2005-03-22 14:53:51 +00:00
|
|
|
glLoadIdentity ();
|
2005-03-25 17:22:10 +00:00
|
|
|
glOrtho (0, width, height, 0, -1, 1); /* 2d */
|
|
|
|
glMatrixMode (GL_MODELVIEW);
|
2005-03-22 14:53:51 +00:00
|
|
|
glLoadIdentity ();
|
|
|
|
|
|
|
|
glEnable (GL_TEXTURE_2D);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
|
|
|
|
return win;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cltr_main_loop()
|
|
|
|
{
|
2005-03-22 17:25:52 +00:00
|
|
|
GMainLoop *loop;
|
|
|
|
|
|
|
|
loop = g_main_loop_new (g_main_context_default (), FALSE);
|
|
|
|
|
|
|
|
CLTR_MARK();
|
|
|
|
|
|
|
|
g_main_loop_run (loop);
|
2005-03-22 14:53:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-03-25 17:22:10 +00:00
|
|
|
gboolean
|
|
|
|
test_idle_cb(gpointer data)
|
|
|
|
{
|
|
|
|
static float angle = 0.0;
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
glClearColor( 0.6, 0.6, 0.62, 1.0);
|
|
|
|
|
|
|
|
glColor3f(0.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
glTranslatef( 0.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
/* get a copy of our untranformed matrix */
|
|
|
|
glPushMatrix();
|
|
|
|
|
|
|
|
/* Translate origin to rotation point */
|
|
|
|
glTranslatef( 320.0, 240.0, 0.0);
|
|
|
|
|
|
|
|
/* Rotate around Z axis */
|
|
|
|
glRotatef ( angle, 0.0, 0.0, 1.0);
|
|
|
|
|
|
|
|
/* Draw tranformed rect with origin at center */
|
|
|
|
glRecti(-50, -50, 50, 50);
|
|
|
|
|
|
|
|
/* Reset our un transformed matrix */
|
|
|
|
glPopMatrix();
|
|
|
|
|
|
|
|
glRecti(-50, -50, 50, 50);
|
|
|
|
|
|
|
|
angle += 0.1;
|
|
|
|
|
|
|
|
glXSwapBuffers(CltrCntx.xdpy, (Window)data);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-03-22 14:53:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
ClutterPhotoGrid *grid = NULL;
|
|
|
|
ClutterWindow *win = NULL;
|
|
|
|
|
2005-03-24 16:46:49 +00:00
|
|
|
if (argc < 2)
|
|
|
|
{
|
|
|
|
g_printerr("usage: '%s' <path to not too heavily populated image dir>\n"
|
|
|
|
, argv[0]);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2005-03-22 14:53:51 +00:00
|
|
|
cltr_init(&argc, &argv);
|
|
|
|
|
|
|
|
win = cltr_window_new(640, 480);
|
|
|
|
|
2005-03-25 17:22:10 +00:00
|
|
|
grid = cltr_photo_grid_new(win, 4, 4, argv[1]);
|
2005-03-23 17:33:37 +00:00
|
|
|
|
|
|
|
Grid = grid; /* laaaaaazy globals */
|
2005-03-22 14:53:51 +00:00
|
|
|
|
2005-03-27 20:12:19 +00:00
|
|
|
// cltr_photo_grid_redraw(grid);
|
|
|
|
|
|
|
|
// g_idle_add(idle_cb, grid);
|
2005-03-22 14:53:51 +00:00
|
|
|
|
2005-03-27 20:12:19 +00:00
|
|
|
// g_timeout_add (10, idle_cb, grid);
|
2005-03-22 17:25:52 +00:00
|
|
|
|
2005-03-25 17:22:10 +00:00
|
|
|
// g_idle_add(test_idle_cb, (gpointer)win->xwin);
|
|
|
|
|
2005-03-22 14:53:51 +00:00
|
|
|
XFlush(CltrCntx.xdpy);
|
|
|
|
|
2005-03-25 17:22:10 +00:00
|
|
|
XMapWindow(CltrCntx.xdpy, win->xwin);
|
2005-03-22 14:53:51 +00:00
|
|
|
|
2005-03-22 17:25:52 +00:00
|
|
|
XFlush(CltrCntx.xdpy);
|
|
|
|
|
|
|
|
cltr_main_loop();
|
|
|
|
|
2005-03-22 14:53:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|