Skip to content

Commit

Permalink
Add support for input into plain x windows via xtest
Browse files Browse the repository at this point in the history
  • Loading branch information
IMbackK committed Dec 29, 2020
1 parent 71e6186 commit fad2c35
Show file tree
Hide file tree
Showing 6 changed files with 392 additions and 162 deletions.
5 changes: 4 additions & 1 deletion configure.ac
Expand Up @@ -16,7 +16,7 @@ AC_SUBST(LIBVERSION)

AM_CONFIG_HEADER(config.h)

CFLAGS="$CFLAGS -Werror -Wall -Wmissing-prototypes -Wmissing-declarations -fno-strict-aliasing"
CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -Wmissing-declarations -fno-strict-aliasing"

AC_CANONICAL_HOST

Expand Down Expand Up @@ -86,6 +86,9 @@ PKG_CHECK_MODULES(X11, x11)
AC_SUBST(X11_LIBS)
AC_SUBST(X11_CFLAGS)

PKG_CHECK_MODULES(XTST, xtst)
AC_SUBST(XTST_LIBS)

localedir=${datadir}/locale

etcdir=$sysconfdir
Expand Down
4 changes: 3 additions & 1 deletion src/Makefile.am
Expand Up @@ -40,6 +40,8 @@ hildon_im_recache_LDFLAGS = -Wl,--as-needed -rdynamic
libhildon_im_ui_la_SOURCES = \
hildon-im-ui.h \
hildon-im-ui.c \
hildon-im-xcode.h\
hildon-im-xcode.c\
hildon-im-plugin.h \
hildon-im-plugin.c \
hildon-im-widget-loader.c \
Expand All @@ -50,7 +52,7 @@ libhildon_im_ui_la_SOURCES = \
libhildon_im_ui_la_LIBADD = \
$(GTK_LIBS) $(GCONF_LIBS) $(ESD_LIBS) $(HILDON_LIBS) \
$(LIBOSSO_LIBS) $(HILDON_IMF_LIBS) $(GLIB_LIBS) \
$(LIBIMLAYOUTS_LIBS) $(DBUS_LIBS) $(X11_LIBS) -ldl
$(LIBIMLAYOUTS_LIBS) $(DBUS_LIBS) $(X11_LIBS) $(XTST_LIBS) -ldl
libhildon_im_ui_la_LDFLAGS = -Wl,--as-needed -version-info $(LIBVERSION)

hildon_input_methodincludeinstdir = $(includedir)/hildon-input-method
Expand Down
149 changes: 126 additions & 23 deletions src/hildon-im-main.c
Expand Up @@ -49,6 +49,11 @@
#define LOCALE_SIGNAL "locale_changed"
#define LOCALE_RULE "type='signal',interface='" LOCALE_IFACE "',member='" LOCALE_SIGNAL "'"

#define DBUS_IFACE_HIM "org.maemo.him"
#define DBUS_SIGNAL_SET_VISIBLE "set_visible"
#define DBUS_MATCH_RULE "type='signal',interface='" DBUS_IFACE_HIM "',member='" DBUS_SIGNAL_SET_VISIBLE "'"


GtkWidget *keyboard = NULL;

static void
Expand All @@ -58,7 +63,7 @@ handle_sigterm(gint t)
}

static DBusHandlerResult
dbus_msg_handler (DBusConnection *connection,
dbus_system_msg_handler (DBusConnection *connection,
DBusMessage *msg,
void *user_data)
{
Expand Down Expand Up @@ -93,45 +98,111 @@ dbus_msg_handler (DBusConnection *connection,
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

int
main(int argc, char *argv[])
static DBusHandlerResult
dbus_msg_handler (DBusConnection *connection,
DBusMessage *msg,
void *user_data)
{
struct sigaction sv;
DBusConnection *dbus_connection = NULL;
DBusError dbus_error_code;
#if !GLIB_CHECK_VERSION(2,32,0)
if (!g_thread_supported ()) g_thread_init (NULL);
#endif
hildon_gtk_init(&argc, &argv);
/* TODO call hildon_init() here
* or replace both calls with hildon_gtk_init() */

gconf_init(argc, argv, NULL);
const char *interface = dbus_message_get_interface(msg);
const char *method = dbus_message_get_member(msg);
const char *sender = dbus_message_get_sender(msg);
gint message_type = -1;

if (!(message_type = dbus_message_get_type(msg)) ||
!sender || !interface || !method)
return FALSE;

if (message_type == DBUS_MESSAGE_TYPE_SIGNAL)
{
if (strcmp(interface, DBUS_IFACE_HIM) == 0 &&
strcmp(method, DBUS_SIGNAL_SET_VISIBLE) == 0)
{
gboolean visible = TRUE;
dbus_message_get_args(msg, NULL,
DBUS_TYPE_BOOLEAN, &visible,
DBUS_TYPE_INVALID);
hildon_im_ui_set_visible((HildonIMUI *)keyboard, visible);
return DBUS_HANDLER_RESULT_HANDLED;
}
}

return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}

setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
static DBusConnection *
register_on_system_dbus()
{
DBusConnection *dbus_connection_system = NULL;
DBusError dbus_error_code;

dbus_error_init(&dbus_error_code);

keyboard = hildon_im_ui_new();
/* Establish DBus connection */
if (!(dbus_connection_system = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error_code)))
{
g_warning("DBUS connection failed: %s\n", dbus_error_code.message);
dbus_error_free (&dbus_error_code);
}

gtk_window_set_accept_focus(GTK_WINDOW(keyboard), FALSE);
if (dbus_connection_system)
{
dbus_bus_add_match(dbus_connection_system, LOCALE_RULE, &dbus_error_code);
if (dbus_error_is_set(&dbus_error_code))
{
g_warning("Unable to add match for locale change: %s\n",
dbus_error_code.message);
dbus_error_free(&dbus_error_code);
}
}

if (!dbus_connection_add_filter(dbus_connection_system,
dbus_system_msg_handler,
NULL, NULL))
{
g_warning("Failed to add filter: %s\n", dbus_error_code.message);
dbus_error_free(&dbus_error_code);
}
return dbus_connection_system;
}

g_signal_connect(keyboard, "destroy", gtk_main_quit, NULL);
static DBusConnection *
register_on_session_dbus()
{
DBusConnection *dbus_connection = NULL;
DBusError dbus_error_code;

dbus_error_init(&dbus_error_code);

/* Establish DBus connection */
if (!(dbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error_code)))
if (!(dbus_connection = dbus_bus_get(DBUS_BUS_SESSION, &dbus_error_code)))
{
g_warning("DBUS connection failed: %s\n", dbus_error_code.message);
dbus_error_free (&dbus_error_code);
}

if (dbus_connection)
{
dbus_bus_add_match(dbus_connection, LOCALE_RULE, &dbus_error_code);
int ret;
ret = dbus_bus_request_name(dbus_connection, DBUS_IFACE_HIM, 0, &dbus_error_code);
if (dbus_error_is_set(&dbus_error_code))
{
g_warning("Unable to add match for locale change: %s\n",
g_warning("Cant own dbus name: %s because: %s\n", DBUS_IFACE_HIM,
dbus_error_code.message);
dbus_error_free(&dbus_error_code);
}
else if (ret == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
{
g_info("Registered dbus interface: %s\n", DBUS_IFACE_HIM);
}
else
{
g_info("Unable to own primary dbus interface name: %s\n", DBUS_IFACE_HIM);
}

dbus_bus_add_match(dbus_connection, DBUS_MATCH_RULE, &dbus_error_code);
if (dbus_error_is_set(&dbus_error_code))
{
g_warning("Unable to add match for set_visible: %s\n",
dbus_error_code.message);
dbus_error_free(&dbus_error_code);
}
Expand All @@ -144,6 +215,38 @@ main(int argc, char *argv[])
g_warning("Failed to add filter: %s\n", dbus_error_code.message);
dbus_error_free(&dbus_error_code);
}
return dbus_connection;
}

int
main(int argc, char *argv[])
{
struct sigaction sv;
DBusConnection *dbus_connection;
DBusConnection *dbus_connection_system;
#if !GLIB_CHECK_VERSION(2,32,0)
if (!g_thread_supported ()) g_thread_init (NULL);
#endif
hildon_gtk_init(&argc, &argv);
/* TODO call hildon_init() here
* or replace both calls with hildon_gtk_init() */

gconf_init(argc, argv, NULL);

setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);

keyboard = hildon_im_ui_new();

gtk_window_set_accept_focus(GTK_WINDOW(keyboard), FALSE);

g_signal_connect(keyboard, "destroy", gtk_main_quit, NULL);

dbus_connection_system = register_on_system_dbus();
dbus_connection = register_on_session_dbus();
(void)dbus_connection;
(void)dbus_connection_system;

/* gtk_main_quit at SIGTERM */
sigemptyset(&sv.sa_mask);
Expand Down

0 comments on commit fad2c35

Please sign in to comment.