Skip to content

Commit

Permalink
Moved to GTK keymap encoding by default when GTK enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
phabrics committed Jul 22, 2024
1 parent f926e40 commit 995d264
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 26 deletions.
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ dnl Checks for display type support
PKG_CHECK_MODULES([GTK], [gtk4], [have_gtk=$enable_gtk], [
PKG_CHECK_MODULES([GTK], [gtk+-3.0], [have_gtk=$enable_gtk], [have_gtk=no])
])
if test "x${have_gtk}" = xyes; then
AC_DEFINE([HAVE_GTK], [], [Defined if GTK is found & enabled.])
fi
AM_CONDITIONAL([HAVE_GTK], [test "x${have_gtk}" = xyes])

PKG_CHECK_MODULES([SDL], [sdl2], [have_sdl=$enable_sdl], [have_sdl=no])

AX_CHECK_COMPILE_FLAG(-sUSE_SDL=2, [have_sdl=$enable_sdl])
Expand Down
2 changes: 1 addition & 1 deletion host/display/rfb/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pkglib_LTLIBRARIES = tme_host_rfb.la
tme_host_rfb_la_SOURCES = rfb-display.c
tme_host_rfb_la_LIBADD = ../libtme-display.la $(RFB_LIBS) $(TME_LIBS)

if HAVE_GLIB
if HAVE_GTK
tme_host_rfb_la_CPPFLAGS += $(GTK_CFLAGS)
tme_host_rfb_la_LIBADD += $(GTK_LIBS)
else
Expand Down
32 changes: 17 additions & 15 deletions host/display/rfb/rfb-display.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,24 @@
/* includes: */
#include "display.h"
#include <rfb/rfb.h>
#ifdef _TME_HAVE_GLIB
#include <stdlib.h>
#ifdef _TME_HAVE_GTK
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#else
#include <SDL.h>

static int _tme_sdl_keymods[] = {
KMOD_SHIFT,
KMOD_NUM | KMOD_CAPS,
KMOD_CTRL,
KMOD_ALT,
KMOD_GUI,
0,
0,
0
};
#endif
#include <stdlib.h>

static const int bpp=4;

Expand Down Expand Up @@ -154,7 +165,7 @@ static void _tme_keyboard_key_ev(int down, tme_keyboard_keyval_t key, rfbClientP
_tme_keyboard_key_event(down, key, cl->clientData);
}

#ifndef _TME_HAVE_GLIB
#ifndef _TME_HAVE_GTK
static tme_keyboard_keyval_t sdl_to_tme_keysym(SDL_Keycode sym) {
tme_keyboard_keyval_t k = 0;

Expand Down Expand Up @@ -329,12 +340,14 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_rfb,display) {

/* start our data structure: */
display = tme_new0(struct tme_display, 1);
#ifdef _TME_HAVE_GLIB

#ifdef _TME_HAVE_GTK
display->tme_display_keyval_name = gdk_keyval_name;
display->tme_display_keyval_from_name = gdk_keyval_from_name;
display->tme_display_keyval_convert_case = gdk_keyval_convert_case;
display->tme_display_key_void_symbol = GDK_KEY_VoidSymbol;
#else
display->tme_display_keymods = _tme_sdl_keymods;
display->tme_display_keyval_name = _tme_sdl_keyval_name;
display->tme_display_keyval_from_name = _tme_sdl_keyval_from_name;
display->tme_display_key_void_symbol = SDLK_UNKNOWN;
Expand Down Expand Up @@ -374,16 +387,5 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_rfb,display) {
display->tme_screen_resize = _tme_rfb_screen_resize;
display->tme_screen_redraw = _tme_rfb_screen_redraw;

#ifdef _TME_HAVE_GLIB
display->tme_display_keyval_name = gdk_keyval_name;
display->tme_display_keyval_from_name = gdk_keyval_from_name;
display->tme_display_keyval_convert_case = gdk_keyval_convert_case;
display->tme_display_key_void_symbol = GDK_KEY_VoidSymbol;
#else
display->tme_display_keyval_name = _tme_sdl_keyval_name;
display->tme_display_keyval_from_name = _tme_sdl_keyval_from_name;
display->tme_display_key_void_symbol = SDLK_UNKNOWN;
#endif

return (TME_OK);
}
5 changes: 5 additions & 0 deletions host/display/sdl/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ pkglib_LTLIBRARIES = tme_host_sdl.la
tme_host_sdl_la_SOURCES = sdl-display.c
tme_host_sdl_la_LIBADD = ../libtme-display.la $(SDL_LIBS) $(TME_LIBS)

if HAVE_GTK
tme_host_sdl_la_CPPFLAGS += $(GTK_CFLAGS)
tme_host_sdl_la_LIBADD += $(GTK_LIBS)
endif

include $(top_srcdir)/modules.mk
42 changes: 32 additions & 10 deletions host/display/sdl/sdl-display.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@
#include "display.h"
#include <SDL.h>
#include <signal.h>
#include <stdlib.h>
#ifdef HAVE_X11_KEYSYM_H
#include <X11/keysym.h>
#elif HAVE_RFB_KEYSYM_H
#include <rfb/keysym.h>
#else
#elif !defined(_TME_HAVE_GTK)
#error "No keysym header file on system."
#endif
#ifdef _TME_HAVE_GTK
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#endif

static int _tme_sdl_keymods[] = {
KMOD_SHIFT,
Expand Down Expand Up @@ -95,6 +100,7 @@ static int _tme_sdl_screen_resize(struct tme_sdl_screen *screen)
int width = conn_fb->tme_fb_connection_width;
int height = conn_fb->tme_fb_connection_height;
int depth = SDL_BITSPERPIXEL(SDL_PIXELFORMAT_RGBA32);
float scaleX, scaleY;
struct tme_display *display;

if (enableResizable)
Expand Down Expand Up @@ -149,9 +155,15 @@ static int _tme_sdl_screen_resize(struct tme_sdl_screen *screen)
tme_log(&display->tme_display_element->tme_element_log_handle, 0, TME_OK,
(&display->tme_display_element->tme_element_log_handle,
_("resize: error creating renderer: %s\n"), SDL_GetError()));
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); /* make the scaled rendering look smoother. */
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best"); /* make the scaled rendering look smoother. */
}
SDL_RenderSetLogicalSize(screen->sdlRenderer, width, height); /* this is a departure from the SDL1.2-based version, but more in the sense of a VNC viewer in keeeping aspect ratio */
SDL_RenderGetScale(screen->sdlRenderer, &scaleX, &scaleY);

tme_log(&display->tme_display_element->tme_element_log_handle, 0, TME_OK,
(&display->tme_display_element->tme_element_log_handle,
_("resize: renderer scale: %f %f\n"), scaleX, scaleY));

/* (re)create the texture that sits in between the surface->pixels and the renderer */
if(screen->sdlTexture)
SDL_DestroyTexture(screen->sdlTexture);
Expand Down Expand Up @@ -244,6 +256,7 @@ static tme_keyboard_keyval_t sdl_to_tme_keysym(SDL_Keycode sym) {
return k;
}

#ifndef _TME_HAVE_GTK
static SDL_Keycode tme_to_sdl_keysym(tme_keyboard_keyval_t sym) {
SDL_Keycode k = 0;

Expand Down Expand Up @@ -334,6 +347,16 @@ static tme_keyboard_keyval_t utf8char2rfbKeySym(const char chr[4]) {
}
return codep;
}

static char *_tme_sdl_keyval_name(tme_keyboard_keyval_t sym) {
return SDL_GetKeyName(tme_to_sdl_keysym(sym));
}

static tme_keyboard_keyval_t _tme_sdl_keyval_from_name(const char *name) {
return sdl_to_tme_keysym(SDL_GetKeyFromName(name));
}
#endif

static void
_tme_sdl_screen_redraw(struct tme_sdl_screen *screen, int x, int y, int w, int h)
{
Expand Down Expand Up @@ -463,14 +486,6 @@ _tme_sdl_display_update(struct tme_display *display) {
return TRUE;
}

static char *_tme_sdl_keyval_name(tme_keyboard_keyval_t sym) {
return SDL_GetKeyName(tme_to_sdl_keysym(sym));
}

static tme_keyboard_keyval_t _tme_sdl_keyval_from_name(const char *name) {
return sdl_to_tme_keysym(SDL_GetKeyFromName(name));
}

/* the new SDL display function: */
TME_ELEMENT_SUB_NEW_DECL(tme_host_sdl,display) {
struct tme_display *display;
Expand All @@ -480,10 +495,17 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_sdl,display) {

/* start our data structure: */
display = tme_new0(struct tme_display, 1);
#ifdef _TME_HAVE_GTK
display->tme_display_keyval_name = gdk_keyval_name;
display->tme_display_keyval_from_name = gdk_keyval_from_name;
display->tme_display_keyval_convert_case = gdk_keyval_convert_case;
display->tme_display_key_void_symbol = GDK_KEY_VoidSymbol;
#else
display->tme_display_keymods = _tme_sdl_keymods;
display->tme_display_keyval_name = _tme_sdl_keyval_name;
display->tme_display_keyval_from_name = _tme_sdl_keyval_from_name;
display->tme_display_key_void_symbol = SDLK_UNKNOWN;
#endif
tme_display_init(element, display);

/* recover our data structure: */
Expand Down

0 comments on commit 995d264

Please sign in to comment.