[gnome-usage] Add support for GameMode
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-usage] Add support for GameMode
- Date: Tue, 16 Jul 2019 13:37:34 +0000 (UTC)
commit b8890b28f24d5b7d629adbd989d3b0bec3a781e1
Author: Christian Kellner <christian kellner me>
Date: Mon Jul 15 19:26:13 2019 +0200
Add support for GameMode
Indicate if a process has requested GameMode by displaying the
applications-games-symbolic icon next to the load level.
data/ui/process-row.ui | 16 +++++++
src/app-item.vala | 6 +++
src/game-mode.vala | 123 ++++++++++++++++++++++++++++++++++++++++++++++++
src/meson.build | 1 +
src/process-row.vala | 4 ++
src/process.vala | 2 +
src/system-monitor.vala | 3 ++
7 files changed, 155 insertions(+)
---
diff --git a/data/ui/process-row.ui b/data/ui/process-row.ui
index ab19f7c..eed02d2 100644
--- a/data/ui/process-row.ui
+++ b/data/ui/process-row.ui
@@ -57,6 +57,22 @@
<property name="position">3</property>
</packing>
</child>
+ <child>
+ <object class="GtkImage" id="gamemode">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_left">10</property>
+ <property name="margin_right">10</property>
+ <property name="pixel_size">24</property>
+ <property name="icon_name">applications-games-symbolic</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
<child>
<object class="GtkBox" id="user_tag_box">
<property name="visible">False</property>
diff --git a/src/app-item.vala b/src/app-item.vala
index 244218f..d25fb8c 100644
--- a/src/app-item.vala
+++ b/src/app-item.vala
@@ -9,6 +9,7 @@ namespace Usage
public double cpu_load { get; private set; }
public uint64 mem_usage { get; private set; }
public Fdo.AccountsUser? user { get; private set; default = null; }
+ public bool gamemode {get; private set; }
private static HashTable<string, AppInfo>? apps_info;
private AppInfo? app_info = null;
@@ -37,6 +38,7 @@ namespace Usage
display_name = find_display_name();
processes.insert(process.pid, process);
load_user_account.begin();
+ gamemode = process.gamemode;
}
public AppItem.system() {
@@ -85,6 +87,7 @@ namespace Usage
public void remove_processes() {
cpu_load = 0;
mem_usage = 0;
+ int games = 0;
foreach(var process in processes.get_values()) {
if(!process.mark_as_updated)
@@ -93,8 +96,11 @@ namespace Usage
cpu_load += process.cpu_load;
mem_usage += process.mem_usage;
}
+ if(process.gamemode)
+ games++;
}
+ gamemode = games > 0;
cpu_load = double.min(100, cpu_load);
}
diff --git a/src/game-mode.vala b/src/game-mode.vala
new file mode 100644
index 0000000..af85388
--- /dev/null
+++ b/src/game-mode.vala
@@ -0,0 +1,123 @@
+/* Generated by vala-dbus-binding-tool 1.0-aa2fb. Do not modify! Haha, but I did. Beat me! */
+/* Generated with: vala-dbus-binding-tool --no-synced --api-path=com.feralinteractive.GameMode.xml */
+using GLib;
+
+[DBus (name = "com.feralinteractive.GameMode.Game", timeout = 120000)]
+public interface GameMode.Game : GLib.Object {
+
+ [DBus (name = "ProcessId")]
+ public abstract int process_id { get; }
+
+ [DBus (name = "Executable")]
+ public abstract string executable { owned get; }
+}
+
+[DBus (name = "com.feralinteractive.GameMode", timeout = 120000)]
+public interface GameMode.Client : GLib.Object {
+
+ [DBus (name = "ClientCount")]
+ public abstract int client_count { get; }
+
+ [DBus (name = "RegisterGame")]
+ public abstract int register_game(int pid) throws DBusError, IOError;
+
+ [DBus (name = "UnregisterGame")]
+ public abstract int unregister_game(int pid) throws DBusError, IOError;
+
+ [DBus (name = "QueryStatus")]
+ public abstract int query_status(int pid) throws DBusError, IOError;
+
+ [DBus (name = "RegisterGameByPID")]
+ public abstract int register_game_by_pid(int pid, int requestor) throws DBusError, IOError;
+
+ [DBus (name = "UnregisterGameByPID")]
+ public abstract int unregister_game_by_pid(int pid, int requestor) throws DBusError, IOError;
+
+ [DBus (name = "QueryStatusByPID")]
+ public abstract int query_status_by_pid(int pid, int requestor) throws DBusError, IOError;
+
+ [DBus (name = "RefreshConfig")]
+ public abstract int refresh_config() throws DBusError, IOError;
+
+ [DBus (name = "ListGames")]
+ public abstract GameInfo[] list_games() throws DBusError, IOError;
+
+ [DBus (name = "GameRegistered")]
+ public signal void game_registered(int pid, GLib.ObjectPath path);
+
+ [DBus (name = "GameUnregistered")]
+ public signal void game_unregistered(int pid, GLib.ObjectPath path);
+}
+
+public struct GameMode.GameInfo {
+ public int pid;
+ public GLib.ObjectPath path;
+}
+
+public class GameMode.PidList : GLib.Object {
+
+ private Client client;
+ private HashTable<int, GLib.ObjectPath> _pids;
+
+ /* singelton */
+ private static PidList singelton;
+
+ public static PidList get_default() {
+ if (singelton == null)
+ singelton = new PidList();
+
+ return singelton;
+ }
+
+ /* construction */
+ construct {
+ _pids = new HashTable<int, GLib.ObjectPath>(direct_hash, direct_equal);
+ }
+
+ public PidList() {
+
+ try {
+ client = Bus.get_proxy_sync(BusType.SESSION,
+ "com.feralinteractive.GameMode",
+ "/com/feralinteractive/GameMode");
+
+ client.game_registered.connect(this.on_game_registered);
+ client.game_unregistered.connect(this.on_game_unregistered);
+
+ var games = client.list_games();
+ foreach (GameMode.GameInfo info in games) {
+ _pids.insert(info.pid, info.path);
+ }
+
+ } catch(IOError e) {
+ warning("GameMode Proxy creation failed: %s", e.message);
+ } catch(GLib.DBusError e) {
+ warning("GameMode D-Bus error: %s", e.message);
+ }
+ }
+
+ /* public */
+ public int[] pids {
+ owned get {
+ return _pids.get_keys_as_array();
+ }
+ }
+
+ public bool contains(int pid) {
+ return pid in _pids;
+ }
+
+ [Signal (detailed = true)]
+ public signal void changed(int pid, bool added);
+
+ /* Signals */
+ private void on_game_registered(int pid, GLib.ObjectPath path) {
+ _pids.insert(pid, path);
+ changed["added"](pid, true);
+ }
+
+ private void on_game_unregistered(int pid, GLib.ObjectPath path) {
+ _pids.remove(pid);
+ changed["removed"](pid, false);
+ }
+}
\ No newline at end of file
diff --git a/src/meson.build b/src/meson.build
index 404a467..932fdfd 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -8,6 +8,7 @@ vala_sources = [
'cpu-monitor.vala',
'cpu-sub-view.vala',
'gnome-usage.vala',
+ 'game-mode.vala',
'graph-box.vala',
'graph-stacked-renderer.vala',
'graph-stack-switcher.vala',
diff --git a/src/process-row.vala b/src/process-row.vala
index b9de945..e526501 100644
--- a/src/process-row.vala
+++ b/src/process-row.vala
@@ -39,6 +39,9 @@ namespace Usage
[GtkChild]
private Gtk.Box user_tag_box;
+ [GtkChild]
+ private Gtk.Image gamemode;
+
[GtkChild]
private Gtk.Label user_tag_label;
@@ -52,6 +55,7 @@ namespace Usage
this.type = type;
this.app = app;
this.icon.gicon = app.get_icon();
+ this.app.bind_property("gamemode", gamemode, "visible", BindingFlags.SYNC_CREATE);
update();
}
diff --git a/src/process.vala b/src/process.vala
index 0f89c8f..890ac5a 100644
--- a/src/process.vala
+++ b/src/process.vala
@@ -34,6 +34,8 @@ namespace Usage
public uint64 mem_usage { get; set; default = 0; }
+ public bool gamemode { get; set; }
+
public bool mark_as_updated { get; set; default = true; }
public ProcessStatus status { get; private set; default = ProcessStatus.SLEEPING; }
diff --git a/src/system-monitor.vala b/src/system-monitor.vala
index 30f9d37..d92752b 100644
--- a/src/system-monitor.vala
+++ b/src/system-monitor.vala
@@ -33,6 +33,7 @@ namespace Usage
private CpuMonitor cpu_monitor;
private MemoryMonitor memory_monitor;
+ private GameMode.PidList gamemode_pids;
private HashTable<string, AppItem> app_table;
private int process_mode = GTop.KERN_PROC_ALL;
@@ -63,6 +64,7 @@ namespace Usage
cpu_monitor = new CpuMonitor();
memory_monitor = new MemoryMonitor();
+ gamemode_pids = new GameMode.PidList();
app_table = new HashTable<string, AppItem>(str_hash, str_equal);
var settings = Settings.get_default();
@@ -157,6 +159,7 @@ namespace Usage
cpu_monitor.update_process(ref process);
memory_monitor.update_process(ref process);
process.update_status();
+ process.gamemode = gamemode_pids.contains((int) process.pid);
}
private string? sanity_cmd(string commandline)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]