Some changes to improve Gtk+ 3.0 compatibility. Still not working.

This commit is contained in:
Brandon Wright 2011-02-05 06:36:27 -06:00
parent 5e53e209b9
commit 61b7f108b9
12 changed files with 106 additions and 76 deletions

View File

@ -140,8 +140,6 @@ else
CFLAGS="$CFLAGS -fomit-frame-pointer"
fi
CFLAGS="$CFLAGS -DGSEAL_ENABLE -DG_DISABLE_SINGLE_INCLUDES -DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED -DGDK_DISABLE_SINGLE_INCLUDES -DGTK_DISABLE_SINGLE_INCLUDES"
ZSNESFX='#ZSNESFX=yes'
ZSNESC4='#ZSNESC4=yes'
ASMCPU=''
@ -165,6 +163,9 @@ GTK=yes
snes9x_info_display="GTK"
PKG_CHECK_MODULES([GTK], [gtk+-2.0 >= 2.16])
# CFLAGS="$CFLAGS -DUSE_GTK3"
PKG_CHECK_MODULES([GLIB], [gthread-2.0 >= 2.6 gobject-2.0 >= 2.6])
PKG_CHECK_MODULES([LIBXML], [libxml-2.0 >= 2.0])
@ -461,7 +462,6 @@ if test yes = "$OPENGL" ; then
else
if test yes = "$with_opengl" ; then
echo "!!! NOT able to use OpenGL support"
echo "--- Needs gtkglext and OpenGL libraries and headers"
fi
fi

View File

@ -3,6 +3,9 @@
#include <string.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#ifdef USE_GTK3
#include <gdk/gdkkeysyms-compat.h>
#endif
#include "gtk_s9x.h"
#include "gtk_binding.h"

View File

@ -234,6 +234,26 @@ GtkBuilderWindow::set_spin (const char *name, unsigned int value)
return;
}
void
GtkBuilderWindow::combo_box_append (const char *name, const char *value)
{
combo_box_append (GTK_COMBO_BOX (get_widget (name)), value);
}
void
GtkBuilderWindow::combo_box_append (GtkComboBox *combo, const char *value)
{
GtkListStore *store;
GtkTreeIter iter;
store = GTK_LIST_STORE (gtk_combo_box_get_model (combo));
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, value, -1);
return;
}
GtkWindow *
GtkBuilderWindow::get_window (void)
{

View File

@ -28,6 +28,8 @@ class GtkBuilderWindow
unsigned int get_entry_value (const char *name);
const char *get_entry_text (const char *name);
unsigned char get_combo (const char *name);
void combo_box_append (const char *name, const char *value);
void combo_box_append (GtkComboBox *combo, const char *value);
unsigned int get_spin (const char *name);
float get_slider (const char *name);
void set_check (const char *name, unsigned char value);

View File

@ -750,7 +750,7 @@ S9xOpenGLDisplayDriver::create_window (int width, int height)
window_attr.background_pixmap = None;
xwindow = XCreateWindow (display,
GDK_WINDOW_XWINDOW (gtk_widget_get_window (drawing_area)),
GDK_COMPAT_WINDOW_XID (gtk_widget_get_window (drawing_area)),
0,
0,
width,
@ -769,7 +769,11 @@ S9xOpenGLDisplayDriver::create_window (int width, int height)
XMapWindow (display, xwindow);
XSync (display, False);
#if USE_GTK3
gdk_window = gdk_x11_window_foreign_new_for_display (gdk_window_get_display (gtk_widget_get_window (drawing_area)), xwindow);
#else
gdk_window = gdk_window_foreign_new (xwindow);
#endif
XSync (display, False);
gdk_window_set_user_data (gdk_window, drawing_area);
@ -791,7 +795,7 @@ S9xOpenGLDisplayDriver::init_glx (void)
}
xcolormap = XCreateColormap (display,
GDK_WINDOW_XWINDOW (gtk_widget_get_window (drawing_area)),
GDK_COMPAT_WINDOW_XID (gtk_widget_get_window (drawing_area)),
vi->visual,
AllocNone);

View File

@ -30,7 +30,7 @@ S9xXVDisplayDriver::S9xXVDisplayDriver (Snes9xWindow *window,
this->config = config;
this->drawing_area = GTK_WIDGET (window->drawing_area);
display =
gdk_x11_drawable_get_xdisplay (GDK_DRAWABLE (gtk_widget_get_window (drawing_area)));
gdk_x11_display_get_xdisplay (gdk_window_get_display (gtk_widget_get_window (drawing_area)));
last_known_width = last_known_height = -1;
return;
@ -62,7 +62,7 @@ S9xXVDisplayDriver::create_window (int width, int height)
window_attr.background_pixmap = None;
xwindow = XCreateWindow (display,
GDK_WINDOW_XWINDOW (gtk_widget_get_window (drawing_area)),
GDK_COMPAT_WINDOW_XID (gtk_widget_get_window (drawing_area)),
0,
0,
width,
@ -81,7 +81,11 @@ S9xXVDisplayDriver::create_window (int width, int height)
XMapWindow (display, xwindow);
XSync (display, False);
#if USE_GTK3
gdk_window = gdk_x11_window_foreign_new_for_display (gdk_window_get_display (gtk_widget_get_window (drawing_area)), xwindow);
#else
gdk_window = gdk_window_foreign_new (xwindow);
#endif
XSync (display, False);
gdk_window_set_user_data (gdk_window, drawing_area);
@ -269,13 +273,13 @@ S9xXVDisplayDriver::init (void)
/* Setup XV */
gtk_widget_realize (drawing_area);
display = gdk_x11_drawable_get_xdisplay (GDK_DRAWABLE (gtk_widget_get_window (drawing_area)));
display = gdk_x11_display_get_xdisplay (gdk_window_get_display (gtk_widget_get_window (drawing_area)));
screen = gtk_widget_get_screen (drawing_area);
root = gdk_screen_get_root_window (screen);
xv_portid = -1;
XvQueryAdaptors (display,
GDK_WINDOW_XWINDOW (root),
GDK_COMPAT_WINDOW_XID (root),
&num_adaptors,
&adaptors);
@ -441,7 +445,7 @@ S9xXVDisplayDriver::init (void)
XSetWindowAttributes window_attr;
xcolormap = XCreateColormap (display,
GDK_WINDOW_XWINDOW (gtk_widget_get_window (drawing_area)),
GDK_COMPAT_WINDOW_XID (gtk_widget_get_window (drawing_area)),
vi->visual,
AllocNone);

View File

@ -461,7 +461,7 @@ S9xOpenROMDialog (void)
}
result = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_hide_all (dialog);
gtk_widget_hide (dialog);
if (result == GTK_RESPONSE_ACCEPT)
{

View File

@ -1,6 +1,9 @@
#include <string>
#include <stdlib.h>
#include <gdk/gdkkeysyms.h>
#ifdef USE_GTK3
#include <gdk/gdkkeysyms-compat.h>
#endif
#include "gtk_preferences.h"
#include "gtk_config.h"
@ -63,14 +66,6 @@ event_calibrate (GtkButton *widget, gpointer data)
}
#endif
static void
event_style_set (GtkWidget *widget, GtkStyle *previous_style, gpointer data)
{
((Snes9xPreferences *) data)->fix_style ();
return;
}
static void
event_control_toggle (GtkToggleButton *widget, gpointer data)
{
@ -249,7 +244,7 @@ event_shader_select (GtkButton *widget, gpointer data)
result = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_hide_all (dialog);
gtk_widget_hide (dialog);
if (result == GTK_RESPONSE_ACCEPT)
{
@ -311,7 +306,7 @@ event_game_data_browse (GtkButton *widget, gpointer data)
gtk_entry_get_text (entry));
result = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_hide_all (dialog);
gtk_widget_hide (dialog);
if (result == GTK_RESPONSE_ACCEPT)
{
@ -500,8 +495,13 @@ event_about_clicked (GtkButton *widget, gpointer data)
top_level->splash);
monospace = pango_font_description_from_string ("Monospace 7");
#ifdef USE_GTK3
gtk_widget_override_font (about_dialog->get_widget ("about_text_view"),
monospace);
#else
gtk_widget_modify_font (about_dialog->get_widget ("about_text_view"),
monospace);
#endif
pango_font_description_free (monospace);
gtk_window_set_transient_for (about_dialog->get_window (),
@ -527,7 +527,6 @@ Snes9xPreferences::Snes9xPreferences (Snes9xConfig *config) :
{ "hw_accel_changed", G_CALLBACK (event_hw_accel_changed) },
{ "reset_current_joypad", G_CALLBACK (event_reset_current_joypad) },
{ "swap_with", G_CALLBACK (event_swap_with) },
{ "style_set", G_CALLBACK (event_style_set) },
{ "ntsc_composite_preset", G_CALLBACK (event_ntsc_composite_preset) },
{ "ntsc_svideo_preset", G_CALLBACK (event_ntsc_svideo_preset) },
{ "ntsc_rgb_preset", G_CALLBACK (event_ntsc_rgb_preset) },
@ -545,8 +544,6 @@ Snes9xPreferences::Snes9xPreferences (Snes9xConfig *config) :
last_toggled = NULL;
this->config = config;
fix_style ();
gtk_widget_realize (window);
signal_connect (callbacks);
@ -595,22 +592,6 @@ Snes9xPreferences::store_ntsc_settings (void)
return;
}
void
Snes9xPreferences::fix_style (void)
{
GtkStyle *style = gtk_rc_get_style (get_widget ("preferences_notebook"));
gtk_widget_set_style (get_widget ("display_viewport"), style);
gtk_widget_set_style (get_widget ("sound_viewport"), style);
gtk_widget_set_style (get_widget ("emulation_viewport"), style);
gtk_widget_set_style (get_widget ("shortcut_viewport1"), style);
gtk_widget_set_style (get_widget ("shortcut_viewport2"), style);
gtk_widget_set_style (get_widget ("shortcut_viewport3"), style);
gtk_widget_set_style (get_widget ("shortcut_viewport4"), style);
return;
}
void
Snes9xPreferences::move_settings_to_dialog (void)
{
@ -979,7 +960,7 @@ Snes9xPreferences::browse_folder_dialog (void)
S9xGetDirectory (HOME_DIR));
result = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_hide_all (dialog);
gtk_widget_hide (dialog);
if (result == GTK_RESPONSE_ACCEPT)
{
@ -1031,7 +1012,7 @@ Snes9xPreferences::show (void)
config->xrr_sizes[i].width,
config->xrr_sizes[i].height);
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), size_string);
combo_box_append (GTK_COMBO_BOX (combo), size_string);
}
#endif
}
@ -1042,46 +1023,43 @@ Snes9xPreferences::show (void)
#ifdef USE_HQ2X
combo = get_widget ("scale_method_combo");
gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
_("HQ2x"));
gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
_("HQ3x"));
gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
_("HQ4x"));
combo_box_append (GTK_COMBO_BOX (combo), _("HQ2x"));
combo_box_append (GTK_COMBO_BOX (combo), _("HQ3x"));
combo_box_append (GTK_COMBO_BOX (combo), _("HQ4x"));
#endif
combo = get_widget ("hw_accel");
gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
combo_box_append (GTK_COMBO_BOX (combo),
_("None - Use software scaler"));
if (config->allow_opengl)
gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
combo_box_append (GTK_COMBO_BOX (combo),
_("OpenGL - Use 3D graphics hardware"));
if (config->allow_xv)
gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
combo_box_append (GTK_COMBO_BOX (combo),
_("XVideo - Use hardware video blitter"));
combo = get_widget ("sound_driver");
#ifdef USE_PORTAUDIO
gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
combo_box_append (GTK_COMBO_BOX (combo),
_("PortAudio"));
#endif
#ifdef USE_OSS
gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
combo_box_append (GTK_COMBO_BOX (combo),
_("Open Sound System"));
#endif
#ifdef USE_JOYSTICK
gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
combo_box_append (GTK_COMBO_BOX (combo),
_("SDL"));
#endif
#ifdef USE_ALSA
gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
combo_box_append (GTK_COMBO_BOX (combo),
_("ALSA"));
#endif
#ifdef USE_PULSEAUDIO
gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
combo_box_append (GTK_COMBO_BOX (combo),
_("PulseAudio"));
#endif

View File

@ -22,7 +22,6 @@ class Snes9xPreferences : public GtkBuilderWindow
int combo_value (int hw_accel);
void focus_next (void);
void swap_with (void);
void fix_style (void);
void reset_current_joypad (void);
void load_ntsc_settings (void);
void store_ntsc_settings (void);

View File

@ -125,8 +125,6 @@ main (int argc, char *argv[])
gtk_window_present (top_level->get_window ());
gdk_threads_lock ();
gtk_main ();
return 0;

View File

@ -36,6 +36,12 @@
extern Snes9xWindow *top_level;
extern Snes9xConfig *gui_config;
#ifdef USE_GTK3
#define GDK_COMPAT_WINDOW_XID(window) (gdk_x11_window_get_xid (window))
#else
#define GDK_COMPAT_WINDOW_XID(window) (GDK_WINDOW_XWINDOW (window))
#endif
int S9xOpenROM (const char *filename);
void S9xNoROMLoaded (void);
void S9xROMLoaded (void);

View File

@ -1,6 +1,9 @@
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <gdk/gdkkeysyms.h>
#ifdef USE_GTK3
#include <gdk/gdkkeysyms-compat.h>
#endif
#include <cairo.h>
#ifdef USE_XV
@ -653,8 +656,10 @@ Snes9xWindow::Snes9xWindow (Snes9xConfig *config) :
gtk_widget_realize (window);
gtk_widget_realize (GTK_WIDGET (drawing_area));
#ifndef USE_GTK3
gdk_window_set_back_pixmap (gtk_widget_get_window (window), NULL, FALSE);
gdk_window_set_back_pixmap (gtk_widget_get_window (GTK_WIDGET (drawing_area)), NULL, FALSE);
#endif
gtk_check_menu_item_set_active (
GTK_CHECK_MENU_ITEM (get_widget ("show_statusbar_item")),
@ -873,7 +878,7 @@ Snes9xWindow::open_movie_dialog (bool readonly)
S9xGetDirectory (SRAM_DIR));
result = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_hide_all (dialog);
gtk_widget_hide (dialog);
if (result == GTK_RESPONSE_ACCEPT)
{
@ -1018,7 +1023,7 @@ Snes9xWindow::load_state_dialog ()
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
result = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_hide_all (dialog);
gtk_widget_hide (dialog);
if (result == GTK_RESPONSE_ACCEPT)
{
@ -1142,7 +1147,7 @@ Snes9xWindow::save_state_dialog ()
result = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_hide_all (dialog);
gtk_widget_hide (dialog);
if (result == GTK_RESPONSE_ACCEPT)
{
@ -1209,7 +1214,7 @@ Snes9xWindow::save_spc_dialog ()
result = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_hide_all (dialog);
gtk_widget_hide (dialog);
if (result == GTK_RESPONSE_ACCEPT)
{
@ -1554,14 +1559,15 @@ Snes9xWindow::enter_fullscreen_mode (void)
}
else
{
Display *display = gdk_x11_drawable_get_xdisplay (GDK_DRAWABLE (gtk_widget_get_window (window)));
GdkDisplay *gdk_display = gdk_window_get_display (gtk_widget_get_window (window));
Display *display = gdk_x11_display_get_xdisplay (gdk_display);
GdkScreen *screen = gtk_widget_get_screen (window);
GdkWindow *root = gdk_screen_get_root_window (screen);
gdk_display_sync (gdk_display_get_default ());
XRRSetScreenConfig (display,
config->xrr_config,
GDK_WINDOW_XWINDOW (root),
GDK_COMPAT_WINDOW_XID (root),
(SizeID) mode,
config->xrr_rotation,
CurrentTime);
@ -1599,13 +1605,14 @@ Snes9xWindow::leave_fullscreen_mode (void)
{
gtk_widget_hide (window);
Display *display = gdk_x11_drawable_get_xdisplay (GDK_DRAWABLE (gtk_widget_get_window (window)));
GdkDisplay *gdk_display = gdk_window_get_display (gtk_widget_get_window (window));
Display *display = gdk_x11_display_get_xdisplay (gdk_display);
GdkScreen *screen = gtk_widget_get_screen (window);
GdkWindow *root = gdk_screen_get_root_window (screen);
XRRSetScreenConfig (display,
config->xrr_config,
GDK_WINDOW_XWINDOW (root),
GDK_COMPAT_WINDOW_XID (root),
(SizeID) config->xrr_original_size,
config->xrr_rotation,
CurrentTime);
@ -1648,7 +1655,16 @@ Snes9xWindow::draw_background (int rect_x, int rect_y, int rect_w, int rect_h)
w = allocation.width;
h = allocation.height;
#ifdef USE_GTK3
GdkRGBA rgba;
gtk_style_context_get_background_color (gtk_widget_get_style_context (widget), GTK_STATE_FLAG_SELECTED, &rgba);
sel.red = rgba.red * 65535;
sel.green = rgba.green * 65535;
sel.blue = rgba.blue * 65535;
#else
sel = gtk_widget_get_style (widget)->bg[GTK_STATE_SELECTED];
#endif
if (rect_x < 0)
{