Commit c3ed3787 authored by Guido Gunther's avatar Guido Gunther

Add keyboard stub

This helps to fullfil gnome-session dependencies on desktops where we
don't have squeekboard (yet) and where it should not unfold
(squeekboard#132).

This can also become the multiplexer for /usr/bin/osk-wayland in the
future making proper keyboard selection part of the shell.

This will also ease creating a test stub to test phosh<->osk
protocol interaction in the future.
Signed-off-by: Guido Gunther's avatarGuido Günther <guido.gunther@puri.sm>
parent 9be1e735
Pipeline #40586 passed with stages
in 8 minutes and 7 seconds
......@@ -4,6 +4,7 @@ desktopconf.set('libexecdir', libexecdir)
desktop_files = [
'sm.puri.Phosh.desktop',
'sm.puri.OSK0.desktop',
]
foreach desktop_file : desktop_files
i18n.merge_file('desktop',
......
[Desktop Entry]
Type=Application
Name=On-screen keyboard stub
Comment=On-screen keyboard stub
Exec=@bindir@/phosh-osk-stub
Categories=GNOME;Core;
OnlyShowIn=GNOME;
NoDisplay=true
X-GNOME-Autostart-Phase=Panel
X-GNOME-Provides=inputmethod
X-GNOME-Autostart-Notify=true
X-GNOME-AutoRestart=true
......@@ -48,3 +48,14 @@ Description: Pure Wayland shell for mobile devices
.
If you're not working on a Wayland compositor then this package is likely not
very useful for you.
Package: phosh-osk-stub
Architecture: any
Depends:
${misc:Depends},
${shlibs:Depends},
Conflicts:
librem5-base
Description: OSK stub to fulfil session dependencies
Phosh's session wants a sm.puri.OSK0. For testing on non-phone's
this stub fulfills the necessary dependencies.
usr/bin/phosh-osk-stub
usr/share/applications/sm.puri.OSK0.desktop
......@@ -9,6 +9,10 @@ stubs = [
'../tests/stubs/toplevel-manager.c',
]
osk_stub_deps = [
gio_dep,
]
executable('app-scroll', ['app-scroll.c'] + stubs,
dependencies: phosh_dep)
......@@ -17,3 +21,7 @@ executable('app-grid-standalone', ['app-grid-standalone.c'] + stubs,
executable('image-notify', ['image-notify.c'] + stubs,
dependencies: phosh_dep)
executable('phosh-osk-stub', ['phosh-osk-stub.c'],
install: true,
dependencies: osk_stub_deps)
/*
* Copyright (C) 2018 Purism SPC
* SPDX-License-Identifier: GPL-3.0+
* Author: Guido Günther <agx@sigxcpu.org>
*/
#define G_LOG_DOMAIN "phosh-osk-stub"
#include "config.h"
#include <gio/gio.h>
#include <glib-unix.h>
#define GNOME_SESSION_DBUS_NAME "org.gnome.SessionManager"
#define GNOME_SESSION_DBUS_OBJECT "/org/gnome/SessionManager"
#define GNOME_SESSION_DBUS_INTERFACE "org.gnome.SessionManager"
#define GNOME_SESSION_CLIENT_PRIVATE_DBUS_INTERFACE "org.gnome.SessionManager.ClientPrivate"
static GMainLoop *loop;
static GDBusProxy *_proxy;
/* TODO:
- handle sm.puri.OSK0
- launch squeekboard if found and fold/unfold on desktops is fixed
https://source.puri.sm/Librem5/squeekboard/issues/132
*/
static void
print_version (void)
{
g_message ("OSK stub %s\n", PHOSH_VERSION);
exit (0);
}
static gboolean
quit_cb (gpointer user_data)
{
g_info ("Caught signal, shutting down...");
if (loop)
g_idle_add ((GSourceFunc) g_main_loop_quit, loop);
else
exit (0);
return FALSE;
}
static void
respond_to_end_session (GDBusProxy *proxy, gboolean shutdown)
{
/* we must answer with "EndSessionResponse" */
g_dbus_proxy_call (proxy, "EndSessionResponse",
g_variant_new ("(bs)", TRUE, ""),
G_DBUS_CALL_FLAGS_NONE,
-1, NULL, NULL, NULL);
}
static void
client_proxy_signal_cb (GDBusProxy *proxy,
gchar *sender_name,
gchar *signal_name,
GVariant *parameters,
gpointer user_data)
{
if (g_strcmp0 (signal_name, "QueryEndSession") == 0) {
g_debug ("Got QueryEndSession signal");
respond_to_end_session (proxy, FALSE);
} else if (g_strcmp0 (signal_name, "EndSession") == 0) {
g_debug ("Got EndSession signal");
respond_to_end_session (proxy, TRUE);
} else if (g_strcmp0 (signal_name, "Stop") == 0) {
g_debug ("Got Stop signal");
quit_cb (NULL);
}
}
static void
on_client_registered (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GVariant *variant;
GDBusProxy *client_proxy;
GError *error = NULL;
gchar *object_path = NULL;
variant = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
if (!variant) {
g_warning ("Unable to register client: %s", error->message);
g_error_free (error);
return;
}
g_variant_get (variant, "(o)", &object_path);
g_debug ("Registered client at path %s", object_path);
client_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, 0, NULL,
GNOME_SESSION_DBUS_NAME,
object_path,
GNOME_SESSION_CLIENT_PRIVATE_DBUS_INTERFACE,
NULL,
&error);
if (!client_proxy) {
g_warning ("Unable to get the session client proxy: %s", error->message);
g_error_free (error);
return;
}
g_signal_connect (client_proxy, "g-signal",
G_CALLBACK (client_proxy_signal_cb), NULL);
g_free (object_path);
g_variant_unref (variant);
}
static void
stub_session_register (const char *client_id)
{
const char *startup_id;
GError *err = NULL;
if (!_proxy) {
_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION,
NULL,
GNOME_SESSION_DBUS_NAME,
GNOME_SESSION_DBUS_OBJECT,
GNOME_SESSION_DBUS_INTERFACE,
NULL,
&err);
if (!_proxy) {
g_debug ("Failed to contact gnome-session: %s", err->message);
g_clear_error (&err);
return;
}
};
startup_id = g_getenv ("DESKTOP_AUTOSTART_ID");
g_dbus_proxy_call (_proxy,
"RegisterClient",
g_variant_new ("(ss)", client_id, startup_id ? startup_id : ""),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
(GAsyncReadyCallback) on_client_registered,
NULL);
}
int main(int argc, char *argv[])
{
g_autoptr(GSource) sigterm = NULL;
g_autoptr(GOptionContext) opt_context = NULL;
GError *err = NULL;
gboolean version = FALSE;
const GOptionEntry options [] = {
{"version", 0, 0, G_OPTION_ARG_NONE, &version,
"Show version information", NULL},
{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
};
opt_context = g_option_context_new ("- A OSK stub for phosh");
g_option_context_add_main_entries (opt_context, options, NULL);
if (!g_option_context_parse (opt_context, &argc, &argv, &err)) {
g_warning ("%s", err->message);
g_clear_error (&err);
return 1;
}
if (version) {
print_version ();
}
stub_session_register ("sm.puri.OSK0");
loop = g_main_loop_new (NULL, FALSE);
g_unix_signal_add (SIGTERM, quit_cb, NULL);
g_unix_signal_add (SIGINT, quit_cb, NULL);
g_main_loop_run (loop);
g_main_loop_unref (loop);
g_object_unref (_proxy);
return EXIT_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment