diff --git a/nwg_panel/main.py b/nwg_panel/main.py
index cb99e28..e78d2a9 100644
--- a/nwg_panel/main.py
+++ b/nwg_panel/main.py
@@ -352,7 +352,9 @@ def main():
if not os.path.isfile(cs_file):
common_settings = {
"restart-on-display": True,
- "restart-delay": 500
+ "restart-delay": 500,
+ "processes-backgroud-only": True,
+ "processes-own-only": True
}
save_json(common_settings, cs_file)
else:
diff --git a/nwg_panel/processes.py b/nwg_panel/processes.py
index 900c7ab..7b752e7 100644
--- a/nwg_panel/processes.py
+++ b/nwg_panel/processes.py
@@ -4,10 +4,13 @@ import psutil
from i3ipc import Connection
import gi
gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk, Gdk, GLib, Gio
+from gi.repository import Gtk, Gdk, GLib
-grid = None
+from nwg_panel.tools import get_config_dir, load_json, save_json, check_key, eprint
+
+common_settings = {}
protected = ["systemd", "bash"]
+grid = Gtk.Grid()
theme = Gtk.IconTheme.get_default()
@@ -21,13 +24,16 @@ def terminate(btn, pid):
os.kill(pid, 2)
-def list_processes(box):
+def list_processes(widget, scrolled_window):
tree = Connection().get_tree()
processes = {}
for proc in psutil.process_iter(['pid', 'ppid', 'name', 'username']):
- if proc.info['username'] == os.getenv('USER') and proc.info['ppid'] == 1:
- processes[proc.info['pid']] = proc.info['name']
+ # if proc.info['username'] == os.getenv('USER') and proc.info['ppid'] == 1:
+ processes[proc.info['pid']] = proc.info['name']
+
+ for child in scrolled_window.get_children():
+ scrolled_window.remove(child)
global grid
if grid:
@@ -36,26 +42,31 @@ def list_processes(box):
grid = Gtk.Grid.new()
grid.set_row_spacing(6)
grid.set_column_spacing(6)
- box.pack_start(grid, True, True, 0)
+ scrolled_window.add(grid)
lbl = Gtk.Label()
lbl.set_markup("PID")
lbl.set_property("halign", Gtk.Align.END)
grid.attach(lbl, 0, 0, 1, 1)
+ lbl = Gtk.Label()
+ lbl.set_markup("User")
+ lbl.set_property("halign", Gtk.Align.END)
+ grid.attach(lbl, 1, 0, 1, 1)
+
lbl = Gtk.Label()
lbl.set_markup("Name")
lbl.set_property("halign", Gtk.Align.START)
- grid.attach(lbl, 2, 0, 1, 1)
+ grid.attach(lbl, 3, 0, 1, 1)
lbl = Gtk.Label()
lbl.set_markup("Kill")
lbl.set_property("halign", Gtk.Align.START)
- grid.attach(lbl, 3, 0, 1, 1)
+ grid.attach(lbl, 4, 0, 1, 1)
idx = 1
for pid in processes:
- if not tree.find_by_pid(pid):
+ if not tree.find_by_pid(pid) or common_settings["processes-background-only"]:
lbl = Gtk.Label.new(str(pid))
lbl.set_property("halign", Gtk.Align.END)
grid.attach(lbl, 0, idx, 1, 1)
@@ -65,38 +76,73 @@ def list_processes(box):
if theme.lookup_icon(name, 16, Gtk.IconLookupFlags.FORCE_SYMBOLIC):
img = Gtk.Image.new_from_icon_name(name, Gtk.IconSize.MENU)
img.set_property("halign", Gtk.Align.END)
- grid.attach(img, 1, idx, 1, 1)
+ grid.attach(img, 2, idx, 1, 1)
lbl = Gtk.Label.new(name)
lbl.set_property("halign", Gtk.Align.START)
- grid.attach(lbl, 2, idx, 1, 1)
-
-
+ grid.attach(lbl, 3, idx, 1, 1)
if processes[pid] not in protected:
btn = Gtk.Button.new_from_icon_name("gtk-close", Gtk.IconSize.MENU)
btn.connect("clicked", terminate, pid)
- grid.attach(btn, 3, idx, 1, 1)
+ grid.attach(btn, 4, idx, 1, 1)
idx += 1
grid.show_all()
return True
+def on_background_cb(check_button):
+ common_settings["processes-background-only"] = check_button.get_active()
+
+
def main():
+ GLib.set_prgname('nwg-processes')
+ global common_settings
+ common_settings = load_json(os.path.join(get_config_dir(), "common-settings.json"))
+ defaults = {
+ "processes-background-only": True,
+ "processes-own-only": True
+ }
+ for key in defaults:
+ check_key(common_settings, key, defaults[key])
+ eprint("Common settings", common_settings)
+
win = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
win.connect('destroy', Gtk.main_quit)
win.connect("key-release-event", handle_keyboard)
- box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
+ box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 6)
box.set_property("margin", 12)
win.add(box)
- list_processes(box)
+ scrolled_window = Gtk.ScrolledWindow.new(None, None)
+ scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.ALWAYS)
+ scrolled_window.set_propagate_natural_width(True)
+ scrolled_window.set_propagate_natural_height(True)
+ box.pack_start(scrolled_window, True, True, 0)
+
+ hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 12)
+ box.pack_start(hbox, False, False, 0)
+
+ cb = Gtk.CheckButton.new_with_label("Background only")
+ cb.set_active(common_settings["processes-background-only"])
+ cb.connect("toggled", on_background_cb)
+ hbox.pack_start(cb, False, False, 6)
+
+ btn = Gtk.Button.new_with_label("Close")
+ hbox.pack_end(btn, False, False, 0)
+ btn.connect("clicked", Gtk.main_quit)
+
+ btn = Gtk.Button.new_with_label("Refresh")
+ hbox.pack_end(btn, False, False, 0)
+ btn.connect("clicked", list_processes, scrolled_window)
+
+ list_processes(None, scrolled_window)
win.show_all()
- GLib.timeout_add(1000, list_processes, box)
+ # GLib.timeout_add(1000, list_processes, scrolled_window)
Gtk.main()