From 6e1faafa2fdd3a94cc901aa7f1dc4f8d9139af46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 21 Nov 2021 20:37:51 +0100 Subject: [PATCH 1/5] main: Remove trailing whitespace --- src/server-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server-main.c b/src/server-main.c index 9a3633f5..6e4e3673 100644 --- a/src/server-main.c +++ b/src/server-main.c @@ -1,10 +1,10 @@ -/* +/* * Copyright (C) 2010-2011 Daiki Ueno * Copyright (C) 2010-2011 Red Hat, Inc. * Copyright (C) 2018-2019 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or From 359376041d0a8f89895d45c89e3dac830453fbee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 21 Nov 2021 19:29:15 +0100 Subject: [PATCH 2/5] main: Honor --help and -h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a GOptionContext to display command line options (that are already handled by e.g. gtk_init anyway). This turns: $ squeekboard -h Debug: Tried file "/home/agx/.local/share/squeekboard/keyboards/us.yaml", but it's missing: No such file or directory (os error 2) Info: Loaded layout Resource: us Debug: Tried file "/home/agx/.local/share/squeekboard/keyboards/us.yaml", but it's missing: No such file or directory (os error 2) Info: Loaded layout Resource: us ** (squeekboard:8015): WARNING **: 19:03:13.125: DBus unavailable, unclear how to continue. Is Squeekboard already running? into the more useful $ squeekboard -h Usage: squeekboard [OPTION…] - A on screen keyboard Help Options: -h, --help Show help options --help-all Show all help options --help-gtk Show GTK+ Options Application Options: --display=DISPLAY X display to use ... --- src/server-main.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/server-main.c b/src/server-main.c index 6e4e3673..fb0e0065 100644 --- a/src/server-main.c +++ b/src/server-main.c @@ -250,6 +250,21 @@ session_register(void) { int main (int argc, char **argv) { + g_autoptr (GError) err = NULL; + g_autoptr(GOptionContext) opt_context = NULL; + + const GOptionEntry options [] = { + { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } + }; + opt_context = g_option_context_new ("- A on screen keyboard"); + + g_option_context_add_main_entries (opt_context, options, NULL); + g_option_context_add_group (opt_context, gtk_get_option_group (TRUE)); + if (!g_option_context_parse (opt_context, &argc, &argv, &err)) { + g_warning ("%s", err->message); + return 1; + } + if (!gtk_init_check (&argc, &argv)) { g_printerr ("Can't init GTK\n"); exit (1); From 475761ec7302c56038b8b00c03bd47ff0d0c4ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 21 Nov 2021 20:26:12 +0100 Subject: [PATCH 3/5] main: Drop broken support G_BUS_TYPE_SYSTEM Fliping opt_system would still use opt_session so drop that. While at that remove G_BUS_TYPE_NONE which can't be set by an option either. --- src/server-main.c | 45 ++++++--------------------------------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/src/server-main.c b/src/server-main.c index fb0e0065..b52705b5 100644 --- a/src/server-main.c +++ b/src/server-main.c @@ -51,8 +51,6 @@ struct squeekboard { GMainLoop *loop; -static gboolean opt_system = FALSE; -static gchar *opt_address = NULL; static void quit (void) @@ -316,46 +314,15 @@ main (int argc, char **argv) // TODO: make dbus errors non-always-fatal // dbus is not strictly necessary for the useful operation // if text-input is used, as it can bring the keyboard in and out - GBusType bus_type; - if (opt_system) { - bus_type = G_BUS_TYPE_SYSTEM; - } else if (opt_address) { - bus_type = G_BUS_TYPE_NONE; - } else { - bus_type = G_BUS_TYPE_SESSION; - } GDBusConnection *connection = NULL; GError *error = NULL; - switch (bus_type) { - case G_BUS_TYPE_SYSTEM: - case G_BUS_TYPE_SESSION: - error = NULL; - connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); - if (connection == NULL) { - g_printerr ("Can't connect to the bus: %s. " - "Visibility switching unavailable.", error->message); - g_error_free (error); - } - break; - case G_BUS_TYPE_NONE: - error = NULL; - connection = g_dbus_connection_new_for_address_sync (opt_address, - 0, - NULL, - NULL, - &error); - if (connection == NULL) { - g_printerr ("Can't connect to the bus at %s: %s\n", - opt_address, - error->message); - g_error_free (error); - exit (1); - } - break; - default: - g_assert_not_reached (); - break; + error = NULL; + connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); + if (connection == NULL) { + g_printerr ("Can't connect to the bus: %s. " + "Visibility switching unavailable.", error->message); + g_error_free (error); } guint owner_id = 0; DBusHandler *service = NULL; From 28a48635b31da3b830396ba6e45d1e11c63386d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 21 Nov 2021 20:47:35 +0100 Subject: [PATCH 4/5] main: Avoid two error variables in the same function This also fixes a superfluous additional `NULL` assignment right after declaring error and setting it to NULL. --- src/server-main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/server-main.c b/src/server-main.c index b52705b5..758639bd 100644 --- a/src/server-main.c +++ b/src/server-main.c @@ -316,13 +316,10 @@ main (int argc, char **argv) // if text-input is used, as it can bring the keyboard in and out GDBusConnection *connection = NULL; - GError *error = NULL; - error = NULL; - connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); + connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &err); if (connection == NULL) { g_printerr ("Can't connect to the bus: %s. " - "Visibility switching unavailable.", error->message); - g_error_free (error); + "Visibility switching unavailable.", err->message); } guint owner_id = 0; DBusHandler *service = NULL; From c3337b05b62f5349abba936e09f198e7b9ff18ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sun, 21 Nov 2021 20:33:41 +0100 Subject: [PATCH 5/5] main: Use dark theme when run in a Phosh session Downstreams either don't restyle making us divert from the designs or use squeekboard-restyled adding extra complexity. Closes: #242 --- src/server-main.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/server-main.c b/src/server-main.c index 758639bd..aba350e5 100644 --- a/src/server-main.c +++ b/src/server-main.c @@ -245,6 +245,32 @@ session_register(void) { g_signal_connect (_client_proxy, "g-signal", G_CALLBACK (client_proxy_signal), NULL); } + +static void +phosh_theme_init (void) +{ + GtkSettings *gtk_settings; + const char *desktop; + gboolean phosh_session; + g_auto (GStrv) components = NULL; + + desktop = g_getenv ("XDG_CURRENT_DESKTOP"); + if (!desktop) { + return; + } + + components = g_strsplit (desktop, ":", -1); + phosh_session = g_strv_contains ((const char * const *)components, "Phosh"); + + if (!phosh_session) { + return; + } + + gtk_settings = gtk_settings_get_default (); + g_object_set (G_OBJECT (gtk_settings), "gtk-application-prefer-dark-theme", TRUE, NULL); +} + + int main (int argc, char **argv) { @@ -270,6 +296,8 @@ main (int argc, char **argv) eek_init (); + phosh_theme_init (); + // Set up Wayland gdk_set_allowed_backends ("wayland"); GdkDisplay *gdk_display = gdk_display_get_default ();