aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorS@P <lorenzotorracchi@mail.com>2025-06-03 23:26:57 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2026-06-12 09:10:49 +0200
commit1e3fa1f9b53a944e294f7f73c94f6e292a20d477 (patch)
tree6dc48f18c8efb321fcce4fb824d31bc5861387be /src
parent8baa1991ac9da904bde8e33f0f0ff90173d13095 (diff)
downloadayatana-indicator-power-1e3fa1f9b53a944e294f7f73c94f6e292a20d477.tar.gz
ayatana-indicator-power-1e3fa1f9b53a944e294f7f73c94f6e292a20d477.tar.bz2
ayatana-indicator-power-1e3fa1f9b53a944e294f7f73c94f6e292a20d477.zip
keep screen on toggle for lomiri
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/keep-screen-on.c93
-rw-r--r--src/keep-screen-on.h35
-rw-r--r--src/service.c19
4 files changed, 148 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f765f23..60f80e6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -13,6 +13,7 @@ set(SERVICE_MANUAL_SOURCES
device-provider-upower.c
device-provider.c
device.c
+ keep-screen-on.c
flashlight.c
notifier.c
testing.c
diff --git a/src/keep-screen-on.c b/src/keep-screen-on.c
new file mode 100644
index 0000000..c9979ac
--- /dev/null
+++ b/src/keep-screen-on.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2025 UBports Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Lorenzo Torracchi <lorenzotorracchi@mail.com>
+ */
+
+#include "keep-screen-on.h"
+
+#include <ayatana/common/utils.h>
+#include <gio/gio.h>
+
+#define UNITY_SCREEN_BUS_NAME "com.canonical.Unity.Screen"
+#define UNITY_SCREEN_OBJECT_PATH "/com/canonical/Unity/Screen"
+#define UNITY_SCREEN_INTERFACE "com.canonical.Unity.Screen"
+
+static guint request_id = 0;
+
+void
+toggle_keep_screen_on_action (GAction *action,
+ GVariant *parameter G_GNUC_UNUSED,
+ gpointer data G_GNUC_UNUSED)
+{
+ GVariant *state = g_action_get_state (action);
+ gboolean enabled = g_variant_get_boolean (state);
+ GError *error = NULL;
+ GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync (
+ G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, UNITY_SCREEN_BUS_NAME,
+ UNITY_SCREEN_OBJECT_PATH, UNITY_SCREEN_INTERFACE, NULL, &error);
+
+ if (!proxy)
+ {
+ g_warning ("Failed to create D-Bus proxy: %s", error->message);
+ g_clear_error (&error);
+ return;
+ }
+ if (!enabled)
+ {
+ GVariant *result
+ = g_dbus_proxy_call_sync (proxy, "keepDisplayOn", NULL,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (result)
+ {
+ g_variant_get (result, "(i)", &request_id);
+ g_variant_unref (result);
+ g_simple_action_set_state (G_SIMPLE_ACTION (action),
+ g_variant_new_boolean (!enabled));
+ }
+ else
+ {
+ g_warning ("D-Bus call keepDisplayOn failed: %s", error->message);
+ g_clear_error (&error);
+ }
+ }
+ else if (request_id != 0)
+ {
+ GVariant *params = g_variant_new ("(i)", request_id);
+ g_dbus_proxy_call_sync (proxy, "removeDisplayOnRequest", params,
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (error)
+ {
+ g_warning ("D-Bus call removeDisplayOnRequest failed: %s",
+ error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ g_simple_action_set_state (G_SIMPLE_ACTION (action),
+ g_variant_new_boolean (!enabled));
+ request_id = 0;
+ }
+ }
+
+ g_object_unref (proxy);
+}
+
+int
+keep_screen_on_supported ()
+{
+ return ayatana_common_utils_is_lomiri ();
+}
diff --git a/src/keep-screen-on.h b/src/keep-screen-on.h
new file mode 100644
index 0000000..81db4b7
--- /dev/null
+++ b/src/keep-screen-on.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2025 UBports Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Lorenzo Torracchi <lorenzotorracchi@mail.com>
+ */
+
+#ifndef INDICATOR_POWER_KEEPSCREENON__H
+#define INDICATOR_POWER_KEEPSCREENON__H
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+void toggle_keep_screen_on_action (GAction *action,
+ GVariant *parameter G_GNUC_UNUSED,
+ gpointer data G_GNUC_UNUSED);
+
+int keep_screen_on_supported ();
+
+G_END_DECLS
+
+#endif /* INDICATOR_POWER_KEEPSCREENON__H */
diff --git a/src/service.c b/src/service.c
index 49bf018..6cfc0aa 100644
--- a/src/service.c
+++ b/src/service.c
@@ -30,6 +30,7 @@
#include "dbus-shared.h"
#include "device.h"
#include "device-provider.h"
+#include "keep-screen-on.h"
#include "notifier.h"
#include "service.h"
#include "flashlight.h"
@@ -681,6 +682,14 @@ create_phone_settings_section(IndicatorPowerService * self)
}
}
+ if (keep_screen_on_supported())
+ {
+ item = g_menu_item_new(_("Keep screen on"), "indicator.keep-screen-on(true)");
+ g_menu_item_set_attribute(item, "x-ayatana-type", "s", "org.ayatana.indicator.switch");
+ g_menu_append_item(section, item);
+ g_object_unref(item);
+ }
+
g_menu_append(section, _("Battery settings…"), "indicator.activate-phone-settings");
return G_MENU_MODEL(section);
@@ -916,6 +925,16 @@ init_gactions (IndicatorPowerService * self)
NULL, NULL);
g_action_map_add_action(G_ACTION_MAP(p->actions), G_ACTION(a));
+ /* add the keep screen on action */
+ if (keep_screen_on_supported())
+ {
+ pType = g_variant_type_new ("b");
+ a = g_simple_action_new_stateful ("keep-screen-on", pType, g_variant_new_boolean (FALSE));
+ g_variant_type_free (pType);
+ g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a));
+ g_signal_connect(a, "change-state", G_CALLBACK(toggle_keep_screen_on_action), p->settings);
+ }
+
/* add the flashlight action */
pType = g_variant_type_new ("b");
a = g_simple_action_new_stateful ("flashlight", pType, g_variant_new_boolean (FALSE));