Skip to content

Commit

Permalink
Add AppIndicator tray support
Browse files Browse the repository at this point in the history
If the AppIndicator gobject library is installed a tray icon
will be shown.

Currently allows switching between a peformance or balanced profile.
  • Loading branch information
vagnum08 committed Jan 18, 2020
1 parent 8831a0f commit dce2a5f
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 60 deletions.
53 changes: 51 additions & 2 deletions README.md
Expand Up @@ -29,6 +29,54 @@ Packages exist in AUR as [`cpupower-gui`](https://aur.archlinux.org/packages/cpu
To install `cpupower-gui` run `updating repos` to update the repositories and install by running `installing cpupower-gui`.


# Usage
## Graphical

To change the frequency settings, select the CPU from the drop-down menu, adjust the sliders and click `Apply`.
Additionally, the cpu governor can be changed by selecting a governor from the drop-down menu.
Last, to apply the same settings to all CPUs, toggle the `All CPUs` switch.

There are two governor profiles available, `Performance` and `Balanced`.
The performance profile sets the governor for all CPUs to `performance`.
Similarly, the balanced profile set the governor to either `powersave` (if available) or to a scalling governor such as `ondemand` or `schedutil`.

These profiles can be selected either from the desktop icon or the tray icon actions.

## Command-line

The governor profiles can be used from the command line.

```bash
$ cpupower-gui -h

Usage:
cpupower-gui [OPTION…]

Help Options:
-h, --help Show help options
--help-all Show all help options
--help-gapplication Show GApplication options
--help-gtk Show GTK+ Options

Application Options:
-p, --performance Change governor to performance
-b, --balanced Change governor to balanced
--display=DISPLAY X display to use

```

For example to switch all governors to performance run `cpupower-gui -p`.
Alternatively, the application actions can be executed via `gapplication`.

```bash
# Switch to balanced profile
gapplication action org.rnd2.cpupower_gui Balanced

# Switch to performance profile
gapplication action org.rnd2.cpupower_gui Performance

```

# Manual Installation
This package uses the [Meson build system](https://mesonbuild.com/) for build configuration and [Ninja](https://ninja-build.org/) as the backend build system.

Expand Down Expand Up @@ -74,7 +122,7 @@ To uninstall run `ninja -C build uninstall`.

# Runtime Dependencies
## Arch Linux and derivatives
`python` `gtk3` `hicolor-icon-theme` `polkit` `python-dbus` `python-gobject`
`python` `gtk3` `hicolor-icon-theme` `polkit` `python-dbus` `python-gobject` `libappindicator-gtk3`

## blackPanther OS and derivatives
`python3`, `gtk3`, `hicolor-icon-theme`, `polkit`, `python3-dbus`, `python3-gobject3`
Expand All @@ -83,6 +131,7 @@ To uninstall run `ninja -C build uninstall`.
`libgtk-3-0` `gir1.2-gtk-3.0` `hicolor-icon-theme` `policykit-1` `python3-dbus` `python3-gi`

Suggested for authentication dialogue: `policykit-1-gnome` or `mate-polkit` or `lxpolkit`
For the tray icon `gir1.2-appindicator3-0.1`.

## Fedora and openSUSE
### Fedora only
Expand All @@ -94,4 +143,4 @@ Suggested for authentication dialogue: `policykit-1-gnome` or `mate-polkit` or `
### Common
`hicolor-icon-theme`

A polkit agent such as `mate-polkit`, `polkit-kde-agent-5`, `policykit-1-gnome`, etc.
A polkit agent such as `mate-polkit`, `polkit-kde-agent-5`, `policykit-1-gnome`, etc.
3 changes: 2 additions & 1 deletion cpupower_gui/cpupower_gui.gresource.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/rnd2/cpupower_gui">
<file>window.glade</file>
<file>window.ui</file>
<file>tray.ui</file>
</gresource>
</gresources>
27 changes: 24 additions & 3 deletions cpupower_gui/main.py
@@ -1,6 +1,6 @@
# main.py
#
# Copyright 2019 Evangelos Rigas
# Copyright 2019-2020 Evangelos Rigas
#
# 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
Expand All @@ -27,6 +27,12 @@

from gi.repository import Gtk, Gio, GLib

try:
gi.require_version("AppIndicator3", "0.1")
from gi.repository import AppIndicator3 as AppIndicator
except:
AppIndicator = None

from .window import CpupowerGuiWindow

BUS = dbus.SystemBus()
Expand All @@ -35,13 +41,13 @@
)

HELPER = dbus.Interface(SESSION, "org.rnd2.cpupower_gui.helper")
APP_ID = "org.rnd2.cpupower_gui"


class Application(Gtk.Application):
def __init__(self):
super().__init__(
application_id="org.rnd2.cpupower_gui",
flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
application_id=APP_ID, flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE
)

self.add_main_option(
Expand Down Expand Up @@ -69,12 +75,27 @@ def __init__(self):
action.connect("activate", self.on_apply_default)
self.add_action(action)

if AppIndicator:
self.indicator = AppIndicator.Indicator.new(
APP_ID, APP_ID, AppIndicator.IndicatorCategory.APPLICATION_STATUS
)
self.indicator.set_status(AppIndicator.IndicatorStatus.ACTIVE)
builder = Gtk.Builder()
builder.add_from_resource("/org/rnd2/cpupower_gui/tray.ui")
builder.get_object("sw_perf").connect("activate", self.on_apply_performance)
builder.get_object("sw_balance").connect("activate", self.on_apply_default)
builder.get_object("quit").connect("activate", self.do_quit)
self.indicator.set_menu(builder.get_object("tray_menu"))

def do_activate(self):
win = self.props.active_window
if not win:
win = CpupowerGuiWindow(application=self)
win.present()

def do_quit(self, *args):
exit(0)

def do_command_line(self, command_line):
options = command_line.get_options_dict()
# convert GVariantDict -> GVariant -> dict
Expand Down
5 changes: 2 additions & 3 deletions cpupower_gui/meson.build
Expand Up @@ -29,12 +29,11 @@ configure_file(


window = configure_file(
input: 'window.glade.in',
output: 'window.glade',
input: 'window.ui.in',
output: 'window.ui',
configuration: conf,
)


gnome.compile_resources('cpupower-gui',
'cpupower_gui.gresource.xml',
gresource_bundle: true,
Expand Down
40 changes: 40 additions & 0 deletions cpupower_gui/tray.ui
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkMenu" id="tray_menu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="menu_type_hint">menu</property>
<child>
<object class="GtkMenuItem" id="sw_perf">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Swith to performance profile</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="sw_balance">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Switch to balanced profile</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem" id="sep">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="quit">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Quit</property>
<property name="use_underline">True</property>
</object>
</child>
</object>
</interface>
28 changes: 2 additions & 26 deletions cpupower_gui/window.py
@@ -1,6 +1,6 @@
# window.py
#
# Copyright 2019 Evangelos Rigas
# Copyright 2019-2020 Evangelos Rigas
#
# 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
Expand Down Expand Up @@ -39,7 +39,6 @@ def dialog_response(widget, response_id):
print("dialog closed or cancelled")
widget.destroy()


def error_message(msg, transient):
message = Gtk.MessageDialog(type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK)
message.set_markup(msg)
Expand All @@ -48,12 +47,11 @@ def error_message(msg, transient):
message.connect("response", dialog_response)


@Gtk.Template(resource_path="/org/rnd2/cpupower_gui/window.glade")
@Gtk.Template(resource_path="/org/rnd2/cpupower_gui/window.ui")
class CpupowerGuiWindow(Gtk.ApplicationWindow):
__gtype_name__ = "CpupowerGuiWindow"

cpu_box = Gtk.Template.Child()
status = Gtk.Template.Child()
gov_box = Gtk.Template.Child()
adj_min = Gtk.Template.Child()
adj_max = Gtk.Template.Child()
Expand All @@ -68,9 +66,6 @@ def __init__(self, **kwargs):
self._read_settings(self._get_active_cpu())

self.upd_sliders()
self.status_icon = self.status
self.status_icon.connect("popup-menu", self.right_click_event)
self.status_icon.connect("activate", self.status_activate)

# Application actions
action = Gio.SimpleAction.new("Exit", None)
Expand All @@ -86,25 +81,6 @@ def update_cpubox(self):
self.cpu_box.set_model(self.cpu_store)
self.cpu_box.set_active(0)

def right_click_event(self, icon, button, time):
"""Handler for right click action on status icon """
self.menu = Gtk.Menu()
about = Gtk.MenuItem()
about.set_label("About")
about.connect("activate", self.on_about_clicked)
self.menu.append(about)
quit = Gtk.MenuItem()
quit.set_label("Quit")
quit.connect("activate", self.quit)
self.menu.append(quit)
self.menu.show_all()
self.menu.popup(None, None, None, self.status_icon, button, time)

def status_activate(self, status_icon):
"""Open window from status icon """
self.deiconify()
self.present()

def quit(self, *args):
"""Quit """
# HELPER.quit()
Expand Down
6 changes: 0 additions & 6 deletions cpupower_gui/window.glade.in → cpupower_gui/window.ui.in
Expand Up @@ -449,10 +449,4 @@ Barcza Károly</property>
</object>
</child>
</template>
<object class="GtkStatusIcon" id="status">
<property name="icon_name">org.rnd2.cpupower_gui</property>
<property name="has_tooltip">True</property>
<property name="tooltip_text" translatable="yes">cpupower-gui</property>
<property name="title" translatable="yes">Frequency Setter</property>
</object>
</interface>
26 changes: 7 additions & 19 deletions org.rnd2.CpupowerGui.json
@@ -1,7 +1,7 @@
{
"app-id": "org.rnd2.CpupowerGui",
"runtime": "org.gnome.Platform",
"runtime-version": "3.24",
"runtime-version": "3.34",
"sdk": "org.gnome.Sdk",
"command": "cpupower-gui",
"finish-args": [
Expand All @@ -16,18 +16,6 @@
"--system-own-name=org.rnd2.cpupower_gui.helper",
"--env=DCONF_USER_CONFIG_DIR=.config/dconf"
],
"build-options" : {
"cflags": "-O2 -g",
"cxxflags": "-O2 -g",
"env": {
"V": "1"
}
},
"cleanup": ["/include", "/lib/pkgconfig",
"/share/pkgconfig", "/share/aclocal",
"/man", "/share/man", "/share/gtk-doc",
"/share/vala",
"*.la", "*.a"],
"cleanup": [
"/include",
"/lib/pkgconfig",
Expand All @@ -43,6 +31,8 @@
"modules": [
{
"name": "cpupower-gui",
"builddir": true,
"buildsystem": "meson",
"sources": [
{
"type": "git",
Expand All @@ -54,16 +44,14 @@
{
"name": "dbus-python",
"buildsystem": "simple",
"ensure-writable": ["easy-install.pth"],
"build-commands": [
"python3 setup.py build -j 0",
"python3 setup.py install --prefix=/app --root=/ --optimize=1"
"pip3 install --prefix=${FLATPAK_DEST} dbus-python==1.2.16"
],
"sources": [
{
"type": "archive",
"url": "https://pypi.python.org/packages/ad/1b/76adc363212c642cabbf9329457a918308c0b9b5d38ce04d541a67255174/dbus-python-1.2.4.tar.gz",
"sha256": "e2f1d6871f74fba23652e51d10873e54f71adab0525833c19bad9e99b1b2f9cc"
"type": "file",
"url": "https://dbus.freedesktop.org/releases/dbus-python/dbus-python-1.2.16.tar.gz",
"sha256": "11238f1d86c995d8aed2e22f04a1e3779f0d70e587caffeab4857f3c662ed5a4"
}
]
}
Expand Down

0 comments on commit dce2a5f

Please sign in to comment.