Search
lxdream.org :: lxdream/src/drivers/video_gtk.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/video_gtk.c
changeset 481:3b2d6c5a19ad
prev477:9a373f2ff009
next485:dfa6bd020c11
author nkeynes
date Wed Oct 31 12:05:23 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Fix miscellaneous warnings
view annotate diff log raw
     1 /**
     2  * $Id: video_gtk.c,v 1.18 2007-10-31 12:05:23 nkeynes Exp $
     3  *
     4  * The PC side of the video support (responsible for actually displaying / 
     5  * rendering frames)
     6  *
     7  * Copyright (c) 2005 Nathan Keynes.
     8  *
     9  * This program is free software; you can redistribute it and/or modify
    10  * it under the terms of the GNU General Public License as published by
    11  * the Free Software Foundation; either version 2 of the License, or
    12  * (at your option) any later version.
    13  *
    14  * This program is distributed in the hope that it will be useful,
    15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    17  * GNU General Public License for more details.
    18  */
    20 #include <gnome.h>
    21 #include <gdk/gdkx.h>
    22 #include <stdint.h>
    23 #include "dream.h"
    24 #include "display.h"
    25 #include "drivers/video_x11.h"
    26 #include "drivers/gl_common.h"
    27 #include "gui/gtkui.h"
    29 static GtkWidget *video_win = NULL;
    30 int video_width = 640;
    31 int video_height = 480;
    33 gboolean video_gtk_init();
    34 void video_gtk_shutdown();
    35 uint16_t video_gtk_resolve_keysym( const gchar *keysym );
    37 struct display_driver display_gtk_driver = { "gtk", video_gtk_init, video_gtk_shutdown,
    38 					     video_gtk_resolve_keysym,
    39 					     NULL, NULL, NULL, NULL, NULL, NULL, NULL };
    41 /**
    42  * Extract the keyval of the key event if no modifier keys were pressed -
    43  * in other words get the keyval of the key by itself. The other way around
    44  * would be to use the hardware keysyms directly rather than the keyvals,
    45  * but the mapping looks to be messier.
    46  */
    47 uint16_t video_gtk_unmodified_keyval( GdkEventKey *event )
    48 {
    49     GdkKeymap *keymap = gdk_keymap_get_default();
    50     guint keyval;
    52     gdk_keymap_translate_keyboard_state( keymap, event->hardware_keycode, 0, 0, &keyval, 
    53 					 NULL, NULL, NULL );
    54     return keyval;
    55 }
    57 gboolean video_gtk_keydown_callback(GtkWidget       *widget,
    58 				     GdkEventKey     *event,
    59 				     gpointer         user_data)
    60 {
    61     input_event_keydown( video_gtk_unmodified_keyval(event) );
    62     return TRUE;
    63 }
    65 gboolean video_gtk_keyup_callback(GtkWidget       *widget,
    66 				  GdkEventKey     *event,
    67 				  gpointer         user_data)
    68 {
    69     input_event_keyup( video_gtk_unmodified_keyval(event) );
    70     return TRUE;
    71 }
    73 uint16_t video_gtk_resolve_keysym( const gchar *keysym )
    74 {
    75     int val = gdk_keyval_from_name( keysym );
    76     if( val == GDK_VoidSymbol )
    77 	return 0;
    78     return (uint16_t)val;
    79 }
    81 gboolean video_gtk_expose_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data )
    82 {
    83     gl_fbo_detach();
    84     gl_redisplay_last();
    85     return TRUE;
    86 }
    88 gboolean video_gtk_resize_callback(GtkWidget *widget, GdkEventConfigure *event, gpointer data )
    89 {
    90     video_width = event->width;
    91     video_height = event->height;
    92     gl_fbo_detach();
    93     gl_redisplay_last();
    94     return TRUE;
    95 }
    97 gboolean video_gtk_init()
    98 {
    99     video_win = gtk_gui_get_renderarea();
   101     g_signal_connect( video_win, "key_press_event", 
   102 		      G_CALLBACK(video_gtk_keydown_callback), NULL );
   103     g_signal_connect( video_win, "key_release_event", 
   104 		      G_CALLBACK(video_gtk_keyup_callback), NULL );
   105     g_signal_connect( video_win, "expose_event",
   106 		      G_CALLBACK(video_gtk_expose_callback), NULL );
   107     g_signal_connect( video_win, "configure_event",
   108 		      G_CALLBACK(video_gtk_resize_callback), NULL );
   109     gtk_widget_add_events( video_win, 
   110 			   GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
   111 			   GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK );
   112     gtk_widget_set_double_buffered( video_win, FALSE );
   113     video_width = video_win->allocation.width;
   114     video_height = video_win->allocation.height;
   115     return video_glx_init( gdk_x11_display_get_xdisplay( gtk_widget_get_display(GTK_WIDGET(video_win))),
   116 			   gdk_x11_screen_get_xscreen( gtk_widget_get_screen(GTK_WIDGET(video_win))),
   117 			   GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ),
   118 			   video_width, video_height, &display_gtk_driver );
   119 }
   121 void video_gtk_shutdown()
   122 {
   123     video_glx_shutdown();
   124     gtk_widget_destroy( GTK_WIDGET(video_win) );
   126 }
.