[gnome-applets] cpufreq: simplify code
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-applets] cpufreq: simplify code
- Date: Sun, 8 Mar 2020 21:36:49 +0000 (UTC)
commit dd65d9073e21e5c9116173066e55fcd1c714ad73
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sun Mar 8 19:31:17 2020 +0200
cpufreq: simplify code
configure.ac | 1 +
cpufreq/src/Makefile.am | 24 ++-
cpufreq/src/cpufreq-applet.c | 1 -
cpufreq/src/cpufreq-popup.c | 94 +++++++---
cpufreq/src/cpufreq-popup.h | 2 -
cpufreq/src/cpufreq-selector.c | 275 ------------------------------
cpufreq/src/cpufreq-selector.h | 50 ------
cpufreq/src/org.gnome.CPUFreqSelector.xml | 23 +++
8 files changed, 117 insertions(+), 353 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 036314c62..bb29e2d93 100644
--- a/configure.ac
+++ b/configure.ac
@@ -79,6 +79,7 @@ dnl ***************************************************************************
IT_PROG_INTLTOOL([0.35.0])
PKG_PROG_PKG_CONFIG([0.19])
+AC_PATH_PROG([GDBUS_CODEGEN], [gdbus-codegen])
AC_PATH_PROG([GLIB_COMPILE_RESOURCES], [glib-compile-resources], [no])
if test x$GLIB_COMPILE_RESOURCES = xno; then
AC_MSG_ERROR([Could not find a glib-compile-resources in your PATH])
diff --git a/cpufreq/src/Makefile.am b/cpufreq/src/Makefile.am
index de84a5f6f..0f33f7d01 100644
--- a/cpufreq/src/Makefile.am
+++ b/cpufreq/src/Makefile.am
@@ -20,6 +20,7 @@ libcpu_frequency_applet_la_CPPFLAGS = \
libcpu_frequency_applet_la_CFLAGS = \
$(GNOME_APPLETS_CFLAGS) \
+ $(GIO_UNIX_CFLAGS) \
$(LIBGLADE_CFLAGS) \
$(WARN_CFLAGS) \
$(AM_CFLAGS) \
@@ -32,12 +33,11 @@ libcpu_frequency_applet_la_SOURCES = \
cpufreq-utils.h \
cpufreq-prefs.c \
cpufreq-prefs.h \
- cpufreq-selector.c \
- cpufreq-selector.h \
cpufreq-popup.c \
cpufreq-popup.h \
cpufreq-monitor.c \
cpufreq-monitor.h \
+ $(BUILT_SOURCES) \
$(NULL)
libcpu_frequency_applet_la_LDFLAGS = \
@@ -48,8 +48,28 @@ libcpu_frequency_applet_la_LDFLAGS = \
libcpu_frequency_applet_la_LIBADD = \
$(GNOME_APPLETS_LIBS) \
+ $(GIO_UNIX_LIBS) \
$(LIBGLADE_LIBS) \
$(LIBCPUFREQ_LIBS) \
$(NULL)
+cpufreq-selector-gen.h:
+cpufreq-selector-gen.c: org.gnome.CPUFreqSelector.xml
+ $(AM_V_GEN) $(GDBUS_CODEGEN) --c-namespace CPUFreq \
+ --generate-c-code cpufreq-selector-gen \
+ $(srcdir)/org.gnome.CPUFreqSelector.xml
+
+BUILT_SOURCES = \
+ cpufreq-selector-gen.c \
+ cpufreq-selector-gen.h \
+ $(NULL)
+
+EXTRA_DIST = \
+ org.gnome.CPUFreqSelector.xml \
+ $(NULL)
+
+CLEANFILES = \
+ $(BUILT_SOURCES) \
+ $(NULL)
+
-include $(top_srcdir)/git.mk
diff --git a/cpufreq/src/cpufreq-applet.c b/cpufreq/src/cpufreq-applet.c
index dd427d6dc..c02aea133 100644
--- a/cpufreq/src/cpufreq-applet.c
+++ b/cpufreq/src/cpufreq-applet.c
@@ -528,7 +528,6 @@ cpufreq_applet_menu_popup (CPUFreqApplet *applet,
if (!applet->popup) {
applet->popup = cpufreq_popup_new ();
cpufreq_popup_set_monitor (applet->popup, applet->monitor);
- cpufreq_popup_set_parent (applet->popup, GTK_WIDGET (applet));
}
menu = cpufreq_popup_get_menu (applet->popup);
diff --git a/cpufreq/src/cpufreq-popup.c b/cpufreq/src/cpufreq-popup.c
index ea05392e9..9b1af428e 100644
--- a/cpufreq/src/cpufreq-popup.c
+++ b/cpufreq/src/cpufreq-popup.c
@@ -26,10 +26,12 @@
#include <string.h>
#include "cpufreq-popup.h"
-#include "cpufreq-selector.h"
+#include "cpufreq-selector-gen.h"
#include "cpufreq-utils.h"
struct _CPUFreqPopupPrivate {
+ CPUFreqSelectorGen *selector;
+
GtkUIManager *ui_manager;
GSList *radio_group;
@@ -44,7 +46,6 @@ struct _CPUFreqPopupPrivate {
gboolean show_freqs;
CPUFreqMonitor *monitor;
- GtkWidget *parent;
};
#define CPUFREQ_POPUP_GET_PRIVATE(object) \
@@ -68,11 +69,61 @@ static const gchar *ui_popup =
#define FREQS_PLACEHOLDER_PATH "/CPUFreqSelectorPopup/FreqsItemsGroup"
#define GOVS_PLACEHOLDER_PATH "/CPUFreqSelectorPopup/GovsItemsGroup"
+static void
+set_frequency_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GError *error;
+
+ error = NULL;
+ cpufreq_selector_gen_call_set_frequency_finish (CPUFREQ_SELECTOR_GEN (source),
+ result, &error);
+
+ if (error != NULL) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+}
+
+static void
+set_governor_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GError *error;
+
+ error = NULL;
+ cpufreq_selector_gen_call_set_governor_finish (CPUFREQ_SELECTOR_GEN (source),
+ result,
+ &error);
+
+ if (error != NULL) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+}
+
static void
cpufreq_popup_init (CPUFreqPopup *popup)
{
+ GError *error;
+
popup->priv = CPUFREQ_POPUP_GET_PRIVATE (popup);
+ error = NULL;
+ popup->priv->selector = cpufreq_selector_gen_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.gnome.CPUFreqSelector",
+
"/org/gnome/cpufreq_selector/selector",
+ NULL,
+ &error);
+
+ if (error != NULL) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+
popup->priv->ui_manager = gtk_ui_manager_new ();
popup->priv->radio_group = NULL;
@@ -107,6 +158,8 @@ cpufreq_popup_finalize (GObject *object)
{
CPUFreqPopup *popup = CPUFREQ_POPUP (object);
+ g_clear_object (&popup->priv->selector);
+
if (popup->priv->ui_manager) {
g_object_unref (popup->priv->ui_manager);
popup->priv->ui_manager = NULL;
@@ -167,61 +220,56 @@ cpufreq_popup_set_monitor (CPUFreqPopup *popup,
popup->priv->monitor = g_object_ref (monitor);
}
-void
-cpufreq_popup_set_parent (CPUFreqPopup *popup,
- GtkWidget *parent)
-{
- g_return_if_fail (CPUFREQ_IS_POPUP (popup));
- g_return_if_fail (GTK_IS_WIDGET (parent));
-
- popup->priv->parent = parent;
-}
-
static void
cpufreq_popup_frequencies_menu_activate (GtkAction *action,
CPUFreqPopup *popup)
{
- CPUFreqSelector *selector;
const gchar *name;
guint cpu;
guint freq;
- guint32 parent;
if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
return;
- selector = cpufreq_selector_get_default ();
+ if (popup->priv->selector == NULL)
+ return;
cpu = cpufreq_monitor_get_cpu (popup->priv->monitor);
name = gtk_action_get_name (action);
freq = (guint) atoi (name + strlen ("Frequency"));
- parent = GDK_WINDOW_XID (gtk_widget_get_window (popup->priv->parent));
-
- cpufreq_selector_set_frequency_async (selector, cpu, freq, parent);
+ cpufreq_selector_gen_call_set_frequency (popup->priv->selector,
+ cpu,
+ freq,
+ NULL,
+ set_frequency_cb,
+ popup);
}
static void
cpufreq_popup_governors_menu_activate (GtkAction *action,
CPUFreqPopup *popup)
{
- CPUFreqSelector *selector;
const gchar *name;
guint cpu;
const gchar *governor;
- guint32 parent;
if (!gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
return;
- selector = cpufreq_selector_get_default ();
+ if (popup->priv->selector == NULL)
+ return;
cpu = cpufreq_monitor_get_cpu (popup->priv->monitor);
name = gtk_action_get_name (action);
governor = name + strlen ("Governor");
- parent = GDK_WINDOW_XID (gtk_widget_get_window (popup->priv->parent));
- cpufreq_selector_set_governor_async (selector, cpu, governor, parent);
+ cpufreq_selector_gen_call_set_governor (popup->priv->selector,
+ cpu,
+ governor,
+ NULL,
+ set_governor_cb,
+ popup);
}
static void
diff --git a/cpufreq/src/cpufreq-popup.h b/cpufreq/src/cpufreq-popup.h
index 13d530f41..8ceaec01c 100644
--- a/cpufreq/src/cpufreq-popup.h
+++ b/cpufreq/src/cpufreq-popup.h
@@ -56,8 +56,6 @@ void cpufreq_popup_set_preferences (CPUFreqPopup *popup,
CPUFreqPrefs *prefs);
void cpufreq_popup_set_monitor (CPUFreqPopup *popup,
CPUFreqMonitor *monitor);
-void cpufreq_popup_set_parent (CPUFreqPopup *popup,
- GtkWidget *parent);
GtkWidget *cpufreq_popup_get_menu (CPUFreqPopup *popup);
G_END_DECLS
diff --git a/cpufreq/src/org.gnome.CPUFreqSelector.xml b/cpufreq/src/org.gnome.CPUFreqSelector.xml
new file mode 100644
index 000000000..d386aad4c
--- /dev/null
+++ b/cpufreq/src/org.gnome.CPUFreqSelector.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.gnome.CPUFreqSelector">
+ <annotation name="org.gtk.GDBus.C.Name" value="SelectorGen" />
+
+ <method name="CanSet">
+ <arg name="result" direction="out" type="b" />
+ </method>
+
+ <method name="SetFrequency">
+ <arg name="cpu" direction="in" type="u" />
+ <arg name="frequency" direction="in" type="u" />
+ </method>
+
+ <method name="SetGovernor">
+ <arg name="cpu" direction="in" type="u" />
+ <arg name="governor" direction="in" type="s" />
+ </method>
+
+ </interface>
+</node>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]