diff --git a/nwg_panel/common.py b/nwg_panel/common.py
index 78a4322..9a094aa 100644
--- a/nwg_panel/common.py
+++ b/nwg_panel/common.py
@@ -28,7 +28,8 @@ commands = {
"netifaces": False,
"btmgmt": False,
"wlr-randr": False,
- "upower": False
+ "upower": False,
+ "swaync": False
}
icons_path = "" # "icons_light", "icons_dark" or "" (GTK icons)
diff --git a/nwg_panel/config.py b/nwg_panel/config.py
index d1bdfcb..49092b7 100644
--- a/nwg_panel/config.py
+++ b/nwg_panel/config.py
@@ -73,7 +73,7 @@ SKELETON_PANEL: dict = {
"margin-right": 0,
"margin-top": 0,
"padding": 2,
- "terminal": "alacritty",
+ "terminal": "foot",
"width": 0
},
"sway-taskbar": {
@@ -448,7 +448,13 @@ class EditorWrapper(object):
Gtk.Widget.set_size_request(self.window, 820, 1)
- self.known_modules = ["clock", "playerctl", "sway-taskbar", "sway-workspaces", "scratchpad"]
+ self.known_modules = ["clock",
+ "playerctl",
+ "sway-taskbar",
+ "sway-workspaces",
+ "scratchpad",
+ "dwl-tags",
+ "swaync"]
self.scrolled_window = builder.get_object("scrolled-window")
@@ -489,6 +495,13 @@ class EditorWrapper(object):
btn = builder.get_object("btn-scratchpad")
btn.connect("clicked", self.edit_scratchpad)
+ btn = builder.get_object("btn-swaync")
+ if is_command("swaync"):
+ btn.connect("clicked", self.edit_swaync)
+ else:
+ btn.set_sensitive(False)
+ btn.set_tooltip_text("The 'swaync' package required")
+
btn = builder.get_object("btn-executors")
btn.connect("clicked", self.select_executor)
@@ -807,6 +820,8 @@ class EditorWrapper(object):
self.update_scratchpad()
elif self.edited == "executor":
self.update_executor()
+ elif self.edited == "swaync":
+ self.update_swaync()
elif self.edited == "button":
self.update_button()
elif self.edited == "modules":
@@ -1044,6 +1059,99 @@ class EditorWrapper(object):
save_json(self.config, self.file)
+ def edit_swaync(self, *args):
+ self.load_panel()
+ self.edited = "swaync"
+ check_key(self.panel, "swaync", {})
+ settings = self.panel["swaync"]
+
+ defaults = {
+ "tooltip-text": "Notifications",
+ "on-left-click": "swaync-client -t",
+ "on-middle-click": "",
+ "on-right-click": "",
+ "on-scroll-up": "",
+ "on-scroll-down": "",
+ "root-css-name": "root-executor",
+ "css-name": "executor",
+ "icon-placement": "left",
+ "icon-size": 18,
+ "interval": 1,
+ "always-show-icon": True
+ }
+ for key in defaults:
+ check_key(settings, key, defaults[key])
+
+ builder = Gtk.Builder.new_from_file(os.path.join(dir_name, "glade/config_swaync.glade"))
+ grid = builder.get_object("grid")
+
+ self.nc_tooltip_text = builder.get_object("tooltip-text")
+ self.nc_tooltip_text.set_text(settings["tooltip-text"])
+
+ self.nc_on_middle_click = builder.get_object("on-middle-click")
+ self.nc_on_middle_click.set_text(settings["on-middle-click"])
+
+ self.nc_on_right_click = builder.get_object("on-right-click")
+ self.nc_on_right_click.set_text(settings["on-right-click"])
+
+ self.nc_on_scroll_up = builder.get_object("on-scroll-up")
+ self.nc_on_scroll_up.set_text(settings["on-scroll-up"])
+
+ self.nc_on_scroll_down = builder.get_object("on-scroll-down")
+ self.nc_on_scroll_down.set_text(settings["on-scroll-down"])
+
+ self.nc_root_css_name = builder.get_object("root-css-name")
+ self.nc_root_css_name.set_text(settings["root-css-name"])
+
+ self.nc_css_name = builder.get_object("css-name")
+ self.nc_css_name.set_text(settings["css-name"])
+
+ self.nc_icon_placement = builder.get_object("icon-placement")
+ self.nc_icon_placement.set_active_id(settings["icon-placement"])
+
+ self.nc_icon_size = builder.get_object("icon-size")
+ self.nc_icon_size.set_numeric(True)
+ adj = Gtk.Adjustment(value=0, lower=8, upper=128, step_increment=1, page_increment=10, page_size=1)
+ self.nc_icon_size.configure(adj, 1, 0)
+ self.nc_icon_size.set_value(settings["icon-size"])
+
+ self.nc_interval = builder.get_object("interval")
+ self.nc_interval.set_numeric(True)
+ adj = Gtk.Adjustment(value=0, lower=1, upper=3600, step_increment=1, page_increment=10, page_size=1)
+ self.nc_interval.configure(adj, 1, 0)
+ self.nc_interval.set_value(settings["interval"])
+
+ self.nc_always_show_icon = builder.get_object("always-show-icon")
+ self.nc_always_show_icon.set_active(settings["always-show-icon"])
+
+ for item in self.scrolled_window.get_children():
+ item.destroy()
+ self.scrolled_window.add(grid)
+
+ def update_swaync(self):
+ settings = self.panel["swaync"]
+
+ settings["tooltip-text"] = self.nc_tooltip_text.get_text()
+ settings["on-middle-click"] = self.nc_on_middle_click.get_text()
+ settings["on-right-click"] = self.nc_on_right_click.get_text()
+ settings["on-scroll-up"] = self.nc_on_scroll_up.get_text()
+ settings["on-scroll-down"] = self.nc_on_scroll_down.get_text()
+ settings["root-css-name"] = self.nc_root_css_name.get_text()
+ settings["css-name"] = self.nc_css_name.get_text()
+
+ val = self.nc_interval.get_value()
+ if val is not None:
+ settings["interval"] = int(val)
+
+ if self.nc_icon_placement.get_active_id():
+ settings["icon-placement"] = self.nc_icon_placement.get_active_id()
+
+ settings["icon-size"] = int(self.nc_icon_size.get_value())
+ settings["interval"] = int(self.nc_interval.get_value())
+ settings["always-show-icon"] = self.nc_always_show_icon.get_active()
+
+ save_json(self.config, self.file)
+
def edit_playerctl(self, *args):
self.load_panel()
self.edited = "playerctl"
@@ -1225,7 +1333,7 @@ class EditorWrapper(object):
"margin-right": 0,
"margin-top": 0,
"padding": 2,
- "terminal": "alacritty",
+ "terminal": "foot",
"width": 0
}
for key in defaults:
diff --git a/nwg_panel/glade/config_main.glade b/nwg_panel/glade/config_main.glade
index e81152c..b64413d 100644
--- a/nwg_panel/glade/config_main.glade
+++ b/nwg_panel/glade/config_main.glade
@@ -19,7 +19,7 @@
True
False
vertical
- 7
+ 4
+
+
+
+ False
+ True
+ 5
+
+
@@ -110,7 +123,7 @@
False
True
- 6
+ 7
@@ -123,7 +136,7 @@
False
True
- 7
+ 8
@@ -136,7 +149,7 @@
False
True
- 8
+ 9
@@ -149,7 +162,7 @@
False
True
- 9
+ 10
@@ -162,7 +175,7 @@
False
True
- 10
+ 11
@@ -175,7 +188,7 @@
False
True
- 11
+ 12
@@ -188,7 +201,7 @@
False
True
- 12
+ 13
@@ -201,7 +214,7 @@
False
True
- 13
+ 14
diff --git a/nwg_panel/glade/config_swaync.glade b/nwg_panel/glade/config_swaync.glade
new file mode 100644
index 0000000..1784ab3
--- /dev/null
+++ b/nwg_panel/glade/config_swaync.glade
@@ -0,0 +1,342 @@
+
+
+
+
+
+
+
diff --git a/nwg_panel/local/executors.json b/nwg_panel/local/executors.json
index 0cba3cc..a24d141 100644
--- a/nwg_panel/local/executors.json
+++ b/nwg_panel/local/executors.json
@@ -3,7 +3,7 @@
"script": "gopsuinfo -i a",
"interval": 2,
"tooltip-text": "CPU average load",
- "on-left-click": "alacritty -e htop",
+ "on-left-click": "foot -e htop",
"on-middle-click": "",
"on-right-click": "",
"on-scroll-up": "",
diff --git a/nwg_panel/main.py b/nwg_panel/main.py
index 583025b..5ff42f2 100644
--- a/nwg_panel/main.py
+++ b/nwg_panel/main.py
@@ -43,6 +43,7 @@ from nwg_panel.modules.playerctl import Playerctl
from nwg_panel.modules.cpu_avg import CpuAvg
from nwg_panel.modules.scratchpad import Scratchpad
from nwg_panel.modules.dwl_tags import DwlTags
+from nwg_panel.modules.swaync import SwayNC
from nwg_panel.modules.menu_start import MenuStart
@@ -398,7 +399,7 @@ def main():
"margin-right": 0,
"margin-top": 0,
"padding": 2,
- "terminal": "alacritty",
+ "terminal": "foot",
"width": 0
}
for key in defaults:
@@ -446,6 +447,12 @@ def main():
common.controls_list.append(cc)
left_box.pack_start(cc, False, False, 0)
+ if common.commands["swaync"]:
+ if "swaync" not in panel:
+ panel["swaync"] = {}
+ sway_nc = SwayNC(panel["swaync"], icons_path)
+ left_box.pack_start(sway_nc, False, False, 0)
+
if panel["menu-start"] == "left":
ms = MenuStart(panel, icons_path=icons_path)
left_box.pack_start(ms, False, False, 0)
@@ -481,6 +488,12 @@ def main():
common.controls_list.append(cc)
right_box.pack_end(cc, False, False, 0)
+ if common.commands["swaync"]:
+ if "swaync" not in panel:
+ panel["swaync"] = {}
+ sway_nc = SwayNC(panel["swaync"], icons_path)
+ right_box.pack_end(sway_nc, False, False, 0)
+
window.add(vbox)
GtkLayerShell.init_for_window(window)
diff --git a/nwg_panel/modules/menu_start.py b/nwg_panel/modules/menu_start.py
index c0a54c6..33619a8 100644
--- a/nwg_panel/modules/menu_start.py
+++ b/nwg_panel/modules/menu_start.py
@@ -61,7 +61,7 @@ class MenuStart(Gtk.Button):
cmd += " -o {}".format(self.panel["output"])
if self.settings["padding"] != 2:
cmd += " -padding {}".format(self.settings["padding"])
- if self.settings["terminal"] != "alacritty":
+ if self.settings["terminal"] != "foot":
cmd += " -term {}".format(self.settings["terminal"])
if self.panel["position"] != "bottom":
cmd += " -va {}".format(self.panel["position"])
diff --git a/nwg_panel/modules/swaync.py b/nwg_panel/modules/swaync.py
new file mode 100644
index 0000000..a2f1bfe
--- /dev/null
+++ b/nwg_panel/modules/swaync.py
@@ -0,0 +1,139 @@
+#!/usr/bin/env python3
+
+from gi.repository import GLib
+
+import subprocess
+import threading
+
+from nwg_panel.tools import check_key, update_image
+
+import gi
+
+gi.require_version('Gtk', '3.0')
+gi.require_version('Gdk', '3.0')
+
+from gi.repository import Gtk, Gdk
+
+
+class SwayNC(Gtk.EventBox):
+ def __init__(self, settings, icons_path):
+ self.settings = settings
+ self.icons_path = icons_path
+ Gtk.EventBox.__init__(self)
+ self.box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
+ self.add(self.box)
+ self.image = Gtk.Image()
+ self.label = Gtk.Label()
+ self.icon_path = None
+
+ check_key(settings, "interval", 1)
+ check_key(settings, "root-css-name", "root-executor")
+ check_key(settings, "css-name", "executor-label")
+ check_key(settings, "icon-placement", "left")
+ check_key(settings, "icon-size", 18)
+ check_key(settings, "tooltip-text", "")
+ check_key(settings, "on-left-click", "swaync-client -t")
+ check_key(settings, "on-right-click", "")
+ check_key(settings, "on-middle-click", "")
+ check_key(settings, "on-scroll-up", "")
+ check_key(settings, "on-scroll-down", "")
+ check_key(settings, "always-show-icon", True)
+
+ update_image(self.image, "view-refresh-symbolic", self.settings["icon-size"], self.icons_path)
+
+ self.set_property("name", settings["root-css-name"])
+
+ if settings["css-name"]:
+ self.label.set_property("name", settings["css-name"])
+ else:
+ self.label.set_property("name", "executor-label")
+
+ if settings["tooltip-text"]:
+ self.set_tooltip_text(settings["tooltip-text"])
+
+ if settings["on-left-click"] or settings["on-right-click"] or settings["on-middle-click"] or settings[
+ "on-scroll-up"] or settings["on-scroll-down"]:
+ self.connect('button-press-event', self.on_button_press)
+ self.add_events(Gdk.EventMask.SCROLL_MASK)
+ self.connect('scroll-event', self.on_scroll)
+
+ self.connect('enter-notify-event', self.on_enter_notify_event)
+ self.connect('leave-notify-event', self.on_leave_notify_event)
+
+ self.build_box()
+ self.refresh()
+
+ if settings["interval"] > 0:
+ Gdk.threads_add_timeout_seconds(GLib.PRIORITY_LOW, settings["interval"], self.refresh)
+
+ def update_widget(self, output):
+ if output:
+ try:
+ num = int(output)
+ if num > 0 or self.settings["always-show-icon"]:
+ if not self.icon_path == "bell":
+ update_image(self.image, "bell", self.settings["icon-size"], self.icons_path)
+ self.icon_path = "bell"
+ self.image.show()
+ else:
+ self.image.hide()
+
+ if num > 0:
+ self.label.set_text(str(num))
+ self.label.show()
+ else:
+ self.label.hide()
+ except:
+ update_image(self.image, "view-refresh-symbolic", self.settings["icon-size"], self.icons_path)
+ self.icon_path = "view-refresh-symbolic"
+ self.image.show()
+
+ return False
+
+ def get_output(self):
+ try:
+ output = subprocess.check_output("swaync-client -c".split()).decode("utf-8")
+ GLib.idle_add(self.update_widget, output)
+ except Exception as e:
+ print(e)
+
+ def refresh(self):
+ thread = threading.Thread(target=self.get_output)
+ thread.daemon = True
+ thread.start()
+ return True
+
+ def build_box(self):
+ if self.settings["icon-placement"] == "left":
+ self.box.pack_start(self.image, False, False, 2)
+ self.box.pack_start(self.label, False, False, 2)
+ if self.settings["icon-placement"] != "left":
+ self.box.pack_start(self.image, False, False, 2)
+
+ def on_enter_notify_event(self, widget, event):
+ widget.set_state_flags(Gtk.StateFlags.DROP_ACTIVE, clear=False)
+ widget.set_state_flags(Gtk.StateFlags.SELECTED, clear=False)
+
+ def on_leave_notify_event(self, widget, event):
+ widget.unset_state_flags(Gtk.StateFlags.DROP_ACTIVE)
+ widget.unset_state_flags(Gtk.StateFlags.SELECTED)
+
+ def on_button_press(self, widget, event):
+ if event.button == 1 and self.settings["on-left-click"]:
+ self.launch(self.settings["on-left-click"])
+ elif event.button == 2 and self.settings["on-middle-click"]:
+ self.launch(self.settings["on-middle-click"])
+ elif event.button == 3 and self.settings["on-right-click"]:
+ self.launch(self.settings["on-right-click"])
+
+ def on_scroll(self, widget, event):
+ if event.direction == Gdk.ScrollDirection.UP and self.settings["on-scroll-up"]:
+ self.launch(self.settings["on-scroll-up"])
+ elif event.direction == Gdk.ScrollDirection.DOWN and self.settings["on-scroll-up"]:
+ self.launch(self.settings["on-scroll-up"])
+ else:
+ print("No command assigned")
+
+ def launch(self, cmd):
+ print("Executing '{}'".format(cmd))
+ subprocess.Popen('exec {}'.format(cmd), shell=True)
diff --git a/setup.py b/setup.py
index 888c6f9..91c5cfc 100644
--- a/setup.py
+++ b/setup.py
@@ -8,7 +8,7 @@ def read(f_name):
setup(
name='nwg-panel',
- version='0.5.8',
+ version='0.6.0',
description='GTK3-based panel for sway window manager',
packages=find_packages(),
include_package_data=True,