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 443:1163eb5c0590
prev436:e8c461d2545e
next449:21440948c684
author nkeynes
date Sat Oct 13 04:01:02 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Add ability to track the last displayed buffer, and handle expose/resize
events appropriately
view annotate diff log raw
     1 /**
     2  * $Id: video_gtk.c,v 1.15 2007-10-13 04:01:02 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 "gui/gtkui.h"
    28 static GtkWidget *video_win = NULL;
    29 int video_width = 640;
    30 int video_height = 480;
    32 gboolean video_gtk_init();
    33 void video_gtk_shutdown();
    34 uint16_t video_gtk_resolve_keysym( const gchar *keysym );
    36 struct display_driver display_gtk_driver = { "gtk", video_gtk_init, video_gtk_shutdown,
    37 					     video_gtk_resolve_keysym,
    38 					     NULL, NULL, NULL, NULL, NULL, NULL, NULL };
    41 gboolean video_gtk_keydown_callback(GtkWidget       *widget,
    42 				     GdkEventKey     *event,
    43 				     gpointer         user_data)
    44 {
    45     input_event_keydown( event->keyval );
    46     return TRUE;
    47 }
    49 uint16_t video_gtk_resolve_keysym( const gchar *keysym )
    50 {
    51     int val = gdk_keyval_from_name( keysym );
    52     if( val == GDK_VoidSymbol )
    53 	return 0;
    54     return (uint16_t)val;
    55 }
    57 gboolean video_gtk_keyup_callback(GtkWidget       *widget,
    58 				  GdkEventKey     *event,
    59 				  gpointer         user_data)
    60 {
    61     input_event_keyup( event->keyval );
    62     return TRUE;
    63 }
    65 gboolean video_gtk_expose_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data )
    66 {
    67     gl_redisplay_last();
    68     return TRUE;
    69 }
    71 gboolean video_gtk_resize_callback(GtkWidget *widget, GdkEventConfigure *event, gpointer data )
    72 {
    73     video_width = event->width;
    74     video_height = event->height;
    75     gl_redisplay_last();
    76     return TRUE;
    77 }
    79 gboolean video_gtk_init()
    80 {
    81     video_win = gtk_gui_get_renderarea();
    83     g_signal_connect( video_win, "key_press_event", 
    84 		      G_CALLBACK(video_gtk_keydown_callback), NULL );
    85     g_signal_connect( video_win, "key_release_event", 
    86 		      G_CALLBACK(video_gtk_keyup_callback), NULL );
    87     g_signal_connect( video_win, "expose_event",
    88 		      G_CALLBACK(video_gtk_expose_callback), NULL );
    89     g_signal_connect( video_win, "configure_event",
    90 		      G_CALLBACK(video_gtk_resize_callback), NULL );
    91     gtk_widget_add_events( video_win, 
    92 			   GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
    93 			   GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK );
    94     gtk_widget_set_double_buffered( video_win, FALSE );
    95     video_width = video_win->allocation.width;
    96     video_height = video_win->allocation.height;
    97     return video_glx_init( gdk_x11_display_get_xdisplay( gtk_widget_get_display(GTK_WIDGET(video_win))),
    98 			   gdk_x11_screen_get_xscreen( gtk_widget_get_screen(GTK_WIDGET(video_win))),
    99 			   GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ),
   100 			   video_width, video_height, &display_gtk_driver );
   101 }
   103 void video_gtk_shutdown()
   104 {
   105     video_glx_shutdown();
   106     gtk_widget_destroy( GTK_WIDGET(video_win) );
   108 }
.