Skip to content
Open
2 changes: 1 addition & 1 deletion discover_overlay/discover_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import importlib_resources
from configparser import ConfigParser
from ctypes import CDLL
from ._version import __version__

CDLL("libgtk4-layer-shell.so")

import gi

from ._version import __version__
from .overlay import OverlayWindow
from .settings_window import Settings
from .voice_overlay import VoiceOverlayWindow
Expand Down
197 changes: 155 additions & 42 deletions discover_overlay/glade/settings.xml

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions discover_overlay/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Collection of LayoutManagers used throughout"""

import logging
from enum import Enum
import gi
Expand Down Expand Up @@ -273,13 +274,23 @@ def do_allocate(self, widget, width, height, _baseline):
lbl_alloc.x = lbl_alloc.y = 0
lbl_alloc.width = width

tx = widget.overlay.text_x_align
if tx == "left":
# i hope this isn't needed anymore
# tx = widget.overlay.text_x_align
# if tx == "left":
# widget.label.set_halign(Gtk.Align.START)
# elif tx == "middle":
# widget.label.set_halign(Gtk.Align.CENTER)
# else:
# widget.label.set_halign(Gtk.Align.END)
if direction == Direction.LTR:
widget.label.set_halign(Gtk.Align.START)
elif tx == "middle":
elif direction == Direction.TTB:
widget.label.set_halign(Gtk.Align.CENTER)
elif direction == Direction.BTT:
widget.label.set_halign(Gtk.Align.CENTER)
else:
widget.label.set_halign(Gtk.Align.END)

ty = widget.overlay.text_y_align
if ty == "top":
widget.label.set_valign(Gtk.Align.START)
Expand All @@ -288,7 +299,7 @@ def do_allocate(self, widget, width, height, _baseline):
else:
widget.label.set_valign(Gtk.Align.END)

widget.image.size_allocate(img_alloc, -1)
widget.image_wrapper.size_allocate(img_alloc, -1)
widget.label.size_allocate(lbl_alloc, -1)
widget.mute.size_allocate(img_alloc, -1)
widget.deaf.size_allocate(img_alloc, -1)
Expand Down
9 changes: 9 additions & 0 deletions discover_overlay/notification_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Notification window for text"""

import logging
import json
import cairo
Expand Down Expand Up @@ -92,10 +93,17 @@ def __init__(self, discover):
self.text_align = "left"
self.align_x = HorzAlign.RIGHT
self.align_y = VertAlign.TOP
self.enabled = False
self.show()

def set_enabled(self, enabled):
"""Set if notifications should be enabled"""
self.enabled = enabled

def add_notification_message(self, data):
"""Add new message to dataset"""
if not self.enabled:
return
if "data" in data:
data = data["data"]
if "body" in data or "title" in data:
Expand Down Expand Up @@ -201,6 +209,7 @@ def update_all(self):

def set_config(self, config):
"""Read in config section and set self and children accordingly"""
self.set_enabled(config.getboolean("enabled", fallback=False))
font = config.get("font", fallback=None)
self.align_x = get_h_align(config.get("align_x", "right"))
self.align_y = get_v_align(config.get("align_y", "top"))
Expand Down
42 changes: 27 additions & 15 deletions discover_overlay/settings_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ def read_config(self):
config.getint("main", "order", fallback=0)
)

self.widget["voice_text_border"].set_active(
config.getboolean("main", "text_border", fallback=True)
)

self.widget["voice_border_width"].set_value(
config.getint("main", "border_width", fallback=2)
)
Expand Down Expand Up @@ -737,7 +741,12 @@ def read_config(self):
def make_colour(self, col):
"""Create a Gdk Color from a col tuple"""
col = json.loads(col)
return Gdk.RGBA(col[0], col[1], col[2], col[3])
rgba = Gdk.RGBA()
rgba.red = col[0]
rgba.green = col[1]
rgba.blue = col[2]
rgba.alpha = col[3]
return rgba

def parse_guild_ids(self, guild_ids_str):
"""Parse the guild_ids from a str and return them in a list"""
Expand Down Expand Up @@ -886,47 +895,47 @@ def voice_display_speakers_grace_period(self, button):
def voice_toggle_test_content(self, button):
self.config_set("main", "show_dummy", f"{button.get_active()}")

def voice_talking_foreground_changed(self, button):
def voice_talking_foreground_changed(self, button, _param=None):
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.config_set("main", "fg_hi_col", json.dumps(colour))

def voice_talking_background_changed(self, button):
def voice_talking_background_changed(self, button, _param=None):
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.config_set("main", "hi_col", json.dumps(colour))

def voice_talking_border_changed(self, button):
def voice_talking_border_changed(self, button, _param=None):
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.config_set("main", "tk_col", json.dumps(colour))

def voice_idle_foreground_changed(self, button):
def voice_idle_foreground_changed(self, button, _param=None):
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.config_set("main", "fg_col", json.dumps(colour))

def voice_idle_background_changed(self, button):
def voice_idle_background_changed(self, button, _param=None):
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.config_set("main", "bg_col", json.dumps(colour))

def voice_idle_border_changed(self, button):
def voice_idle_border_changed(self, button, _param=None):
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.config_set("main", "bo_col", json.dumps(colour))

def voice_mute_foreground_changed(self, button):
def voice_mute_foreground_changed(self, button, _param=None):
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.config_set("main", "mt_col", json.dumps(colour))

def voice_mute_background_changed(self, button):
def voice_mute_background_changed(self, button, _param=None):
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.config_set("main", "mt_bg_col", json.dumps(colour))

def voice_avatar_background_changed(self, button):
def voice_avatar_background_changed(self, button, _param=None):
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.config_set("main", "avatar_bg_col", json.dumps(colour))
Expand All @@ -950,11 +959,14 @@ def voice_fancy_avatar_shapes_changed(self, button):
def voice_order_avatars_by_changed(self, button):
self.config_set("main", "order", f"{button.get_active()}")

def voice_text_border_changed(self, button):
self.config_set("main", "text_border", f"{button.get_active()}")

def voice_border_width_changed(self, button):
self.config_set("main", "border_width", f"{int(button.get_value())}")

def voice_avatar_circle_changed(self, button):
self.config_set("main", "square_avatar", f"{ not button.get_active()}")
self.config_set("main", "square_avatar", f"{not button.get_active()}")

def voice_show_title_changed(self, button):
self.config_set("main", "show_title", f"{button.get_active()}")
Expand Down Expand Up @@ -1028,12 +1040,12 @@ def text_channel_changed(self, button):
def text_font_changed(self, button):
self.config_set("text", "font", button.get_font())

def text_colour_changed(self, button):
def text_colour_changed(self, button, _param=None):
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.config_set("text", "fg_col", json.dumps(colour))

def text_background_colour_changed(self, button):
def text_background_colour_changed(self, button, _param=None):
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.config_set("text", "bg_col", json.dumps(colour))
Expand Down Expand Up @@ -1083,12 +1095,12 @@ def notification_limit_popup_width_changed(self, button):
def notification_font_changed(self, button):
self.config_set("notification", "font", button.get_font())

def notification_text_colour_changed(self, button):
def notification_text_colour_changed(self, button, _param=None):
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.config_set("notification", "fg_col", json.dumps(colour))

def notification_background_colour_changed(self, button):
def notification_background_colour_changed(self, button, _param=None):
colour = button.get_rgba()
colour = [colour.red, colour.green, colour.blue, colour.alpha]
self.config_set("notification", "bg_col", json.dumps(colour))
Expand Down
9 changes: 9 additions & 0 deletions discover_overlay/text_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Overlay window for text"""

import logging
import gi
import cairo
Expand Down Expand Up @@ -45,8 +46,13 @@ def __init__(self, discover):
self.height_limit = 300
self.align_x = HorzAlign.RIGHT
self.align_y = VertAlign.BOTTOM
self.enabled = False
self.show()

def set_enabled(self, enabled):
"""Set if text overlay should be enabled"""
self.enabled = enabled

def set_blank(self):
"""Set contents blank and redraw"""
child = self.get_first_child()
Expand All @@ -58,6 +64,8 @@ def set_blank(self):

def new_line(self, message):
"""Add a new message to text overlay. Does not sanity check the data"""
if not self.enabled:
return
message = Message(self, message)
if not message.skip:
self.append(message)
Expand Down Expand Up @@ -104,6 +112,7 @@ def update_all(self):

def set_config(self, config):
"""Set self and children from config"""
self.set_enabled(config.getboolean("enabled", fallback=False))
channel = config.get("channel", fallback="0")
guild = config.get("guild", fallback="0")
self.discover.connection.set_text_channel(channel, guild)
Expand Down
10 changes: 8 additions & 2 deletions discover_overlay/userbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""A Gtk Box with direction"""

import gettext
import logging
import gi
Expand Down Expand Up @@ -55,9 +56,14 @@ def __init__(self, overlay, userid):
self.deaf = Gtk.Image()

self.image.set_overflow(Gtk.Overflow.HIDDEN)
self.image.add_css_class("usericon-image")

self.image_wrapper = Gtk.Box()
self.image_wrapper.add_css_class("usericon")
self.image_wrapper.append(self.image)

self.image.add_css_class("usericon")
self.label.add_css_class("userlabel")

self.mute.add_css_class("usermute")
self.deaf.add_css_class("userdeaf")

Expand All @@ -69,7 +75,7 @@ def __init__(self, overlay, userid):
self.deaf.set_valign(Gtk.Align.CENTER)

self.append(self.label)
self.append(self.image)
self.append(self.image_wrapper)
self.append(self.mute)
self.append(self.deaf)

Expand Down
Loading