Merge pull request #86 from nwg-piotr/swaync

add swaync integration
This commit is contained in:
Piotr Miller
2022-01-29 03:44:19 +01:00
committed by GitHub
9 changed files with 634 additions and 18 deletions

View File

@@ -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)

View File

@@ -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:

View File

@@ -19,7 +19,7 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">7</property>
<property name="spacing">4</property>
<child>
<object class="GtkButton" id="btn-panel">
<property name="label" translatable="yes">Panel</property>
@@ -87,6 +87,19 @@
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn-swaync">
<property name="label" translatable="yes">Notifications</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn-menu-start">
<property name="label" translatable="yes">Menu Start</property>
@@ -97,7 +110,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
<property name="position">6</property>
</packing>
</child>
<child>
@@ -110,7 +123,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">6</property>
<property name="position">7</property>
</packing>
</child>
<child>
@@ -123,7 +136,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">7</property>
<property name="position">8</property>
</packing>
</child>
<child>
@@ -136,7 +149,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">8</property>
<property name="position">9</property>
</packing>
</child>
<child>
@@ -149,7 +162,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">9</property>
<property name="position">10</property>
</packing>
</child>
<child>
@@ -162,7 +175,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">10</property>
<property name="position">11</property>
</packing>
</child>
<child>
@@ -175,7 +188,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">11</property>
<property name="position">12</property>
</packing>
</child>
<child>
@@ -188,7 +201,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">12</property>
<property name="position">13</property>
</packing>
</child>
<child>
@@ -201,7 +214,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">13</property>
<property name="position">14</property>
</packing>
</child>
</object>

View File

@@ -0,0 +1,342 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<!-- n-columns=3 n-rows=13 -->
<object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="row-spacing">6</property>
<property name="column-spacing">12</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Module :: SwayNC</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
<property name="width">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Tooltip text</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="tooltip-text">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">On left click</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">swaync-client -t</property>
<attributes>
<attribute name="style" value="oblique"/>
</attributes>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">toggles Notification Center on/off</property>
<property name="halign">start</property>
<property name="stock">gtk-about</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">On middle click</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="on-middle-click">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">On right click</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">4</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="on-right-click">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">4</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">On scroll up</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">5</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="on-scroll-up">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">On scroll down</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">6</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="on-scroll-down">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">6</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Root CSS name</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">7</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="root-css-name">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">7</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">CSS name</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">8</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="css-name">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">8</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Icon placement</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">9</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="icon-placement">
<property name="visible">True</property>
<property name="can-focus">False</property>
<items>
<item id="left" translatable="yes">left</item>
<item id="right" translatable="yes">right</item>
</items>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">9</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Icon size</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">10</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="icon-size">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">10</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Interval</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">11</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="interval">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">11</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="always-show-icon">
<property name="label" translatable="yes">Always show icon</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="halign">start</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">12</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</interface>

View File

@@ -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": "",

View File

@@ -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)

View File

@@ -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"])

139
nwg_panel/modules/swaync.py Normal file
View File

@@ -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)

View File

@@ -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,