- Store monitor by plug name

- - Index was inconsistent between different DEs
- - Index was inconsistent when matching monitor models existed
- - Plugname is only inconsistent when switching DEs
- Bugfix for notification overlay
This commit is contained in:
trigg 2024-07-08 15:37:57 +01:00
parent 3d95735c78
commit ce0c1aece3
7 changed files with 115 additions and 93 deletions

View file

@ -56,7 +56,7 @@ class DiscoverAudioAssist:
def thread_loop(self): def thread_loop(self):
# Start an asyncio specific thread. Not the prettiest but I'm not rewriting from ground up for one feature # Start an asyncio specific thread. Not the prettiest but I'm not rewriting from ground up for one feature
log.info("Staring Audio subsystem assistance") log.info("Starting Audio subsystem assistance")
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()
loop.run_until_complete(self.pulse_loop()) loop.run_until_complete(self.pulse_loop())
log.info("Stopped Audio subsystem assistance") log.info("Stopped Audio subsystem assistance")

View file

@ -231,11 +231,6 @@ class Discover:
"main", "highlight_self", fallback=False)) "main", "highlight_self", fallback=False))
self.voice_overlay.set_icon_only(config.getboolean( self.voice_overlay.set_icon_only(config.getboolean(
"main", "icon_only", fallback=False)) "main", "icon_only", fallback=False))
monitor = 0
try:
monitor = config.getint("main", "monitor", fallback=0)
except:
pass
self.voice_overlay.set_vert_edge_padding(config.getint( self.voice_overlay.set_vert_edge_padding(config.getint(
"main", "vert_edge_padding", fallback=0)) "main", "vert_edge_padding", fallback=0))
self.voice_overlay.set_horz_edge_padding(config.getint( self.voice_overlay.set_horz_edge_padding(config.getint(
@ -277,7 +272,9 @@ class Discover:
self.voice_overlay.set_dummy_count(config.getint("main", self.voice_overlay.set_dummy_count(config.getint("main",
"dummy_count", fallback=10)) "dummy_count", fallback=10))
self.voice_overlay.set_monitor(monitor) self.voice_overlay.set_monitor(
config.get("main", "monitor", fallback="Any")
)
self.voice_overlay.set_enabled(True) self.voice_overlay.set_enabled(True)
@ -303,11 +300,6 @@ class Discover:
"text", "rightalign", fallback=True)) "text", "rightalign", fallback=True))
self.text_overlay.set_align_y( self.text_overlay.set_align_y(
config.getint("text", "topalign", fallback=2)) config.getint("text", "topalign", fallback=2))
monitor = 0
try:
monitor = config.getint("text", "monitor", fallback=0)
except:
pass
floating = config.getboolean("text", "floating", fallback=True) floating = config.getboolean("text", "floating", fallback=True)
floating_x = config.getfloat("text", "floating_x", fallback=0.0) floating_x = config.getfloat("text", "floating_x", fallback=0.0)
floating_y = config.getfloat("text", "floating_y", fallback=0.0) floating_y = config.getfloat("text", "floating_y", fallback=0.0)
@ -336,7 +328,9 @@ class Discover:
self.text_overlay.set_mouseover_timer( self.text_overlay.set_mouseover_timer(
config.getint("text", "autohide_timer", fallback=1)) config.getint("text", "autohide_timer", fallback=1))
self.text_overlay.set_monitor(monitor) self.text_overlay.set_monitor(
config.get("text", "monitor", fallback="Any")
)
self.text_overlay.set_floating( self.text_overlay.set_floating(
floating, floating_x, floating_y, floating_w, floating_h) floating, floating_x, floating_y, floating_w, floating_h)
@ -350,11 +344,6 @@ class Discover:
"notification", "rightalign", fallback=True)) "notification", "rightalign", fallback=True))
self.notification_overlay.set_align_y( self.notification_overlay.set_align_y(
config.getint("notification", "topalign", fallback=2)) config.getint("notification", "topalign", fallback=2))
monitor = 0
try:
monitor = config.getint("notification", "monitor", fallback=0)
except:
pass
floating = config.getboolean( floating = config.getboolean(
"notification", "floating", fallback=False) "notification", "floating", fallback=False)
floating_x = config.getfloat( floating_x = config.getfloat(
@ -395,7 +384,9 @@ class Discover:
if self.font: if self.font:
self.notification_overlay.set_font(self.font) self.notification_overlay.set_font(self.font)
self.notification_overlay.set_monitor(monitor) self.notification_overlay.set_monitor(
config.get("notification", "monitor", fallback="Any")
)
self.notification_overlay.set_floating( self.notification_overlay.set_floating(
floating, floating_x, floating_y, floating_w, floating_h) floating, floating_x, floating_y, floating_w, floating_h)
if self.font: if self.font:

View file

@ -22,7 +22,6 @@ try:
from gi.repository import GtkLayerShell from gi.repository import GtkLayerShell
except (ImportError, ValueError): except (ImportError, ValueError):
GtkLayerShell = None GtkLayerShell = None
pass
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View file

@ -83,13 +83,13 @@ class SurfaceGetter():
self.func(self.identifier, surface, mask) self.func(self.identifier, surface, mask)
return return
except ValueError: except ValueError:
errors.append("Value Error - Unable to read %s" % (mixpath)) errors.append("Value Error - Unable to read %s", self.url)
except TypeError: except TypeError:
errors.append("Type Error - Unable to read %s" % (mixpath)) errors.append("Type Error - Unable to read %s", self.url)
except PIL.UnidentifiedImageError: except PIL.UnidentifiedImageError:
errors.append("Unknown image type: %s" % (mixpath)) errors.append("Unknown image type: %s", self.url)
except FileNotFoundError: except FileNotFoundError:
errors.append("File not found: %s" % (mixpath)) errors.append("File not found: %s", self.url)
# Not found in theme, try some common locations # Not found in theme, try some common locations
locations = [os.path.expanduser('~/.local/'), '/usr/', '/app'] locations = [os.path.expanduser('~/.local/'), '/usr/', '/app']
for prefix in locations: for prefix in locations:
@ -150,7 +150,7 @@ def from_pil(image, alpha=1.0, format='BGRa'):
def to_pil(surface): def to_pil(surface):
if surface.get_format() == cairo.Format.ARGB32: if surface.get_format() == cairo.Format.ARGB32:
return Image.frombuffer('RGBA', (surface.get_width(), surface.get_height()), surface.get_data(), 'raw', "BGRA", surface.get_stride()) return Image.frombuffer('RGBA', (surface.get_width(), surface.get_height()), surface.get_data(), 'raw', "BGRA", surface.get_stride())
return Image.frombuffer("RGB", (surface.get_width(), surface.get_height()), surface.get_data(), 'raw', "BGRX", stride) return Image.frombuffer("RGB", (surface.get_width(), surface.get_height()), surface.get_data(), 'raw', "BGRX", surface.get_stride())
def get_surface(func, identifier, ava, size): def get_surface(func, identifier, ava, size):

View file

@ -281,7 +281,7 @@ class NotificationOverlayWindow(OverlayWindow):
return self.test_content return self.test_content
return self.content return self.content
def overlay_draw(self, _w, context, data=None): def overlay_draw(self, w, context, data=None):
""" """
Draw the overlay Draw the overlay
""" """
@ -509,12 +509,12 @@ class NotificationOverlayWindow(OverlayWindow):
return return
# key is the url to the image # key is the url to the image
key = self.image_list[shape.data] key = self.image_list[shape.data]
if key not in self.attachment: if key not in self.icons:
get_surface(self.recv_attach, get_surface(self.recv_attach,
key, key,
key, None) key, None)
return return
pix = self.attachment[key] pix = self.icons[key]
(pos_x, pos_y) = ctx.get_current_point() (pos_x, pos_y) = ctx.get_current_point()
draw_img_to_rect(pix, ctx, pos_x, pos_y - self.text_size, self.text_size, draw_img_to_rect(pix, ctx, pos_x, pos_y - self.text_size, self.text_size,
self.text_size, path=path) self.text_size, path=path)

View file

@ -95,7 +95,7 @@ class OverlayWindow(Gtk.Window):
self.show_all() self.show_all()
if discover.steamos: if discover.steamos:
self.set_gamescope_xatom(1) self.set_gamescope_xatom(1)
self.monitor = 0 self.monitor = "Any"
self.align_right = True self.align_right = True
self.align_vert = 1 self.align_vert = 1
self.floating = False self.floating = False
@ -301,17 +301,14 @@ class OverlayWindow(Gtk.Window):
def get_display_coords(self): def get_display_coords(self):
if self.piggyback_parent: if self.piggyback_parent:
return self.piggyback_parent.get_display_coords() return self.piggyback_parent.get_display_coords()
display = Gdk.Display.get_default() monitor = self.get_monitor_from_plug()
if "get_monitor" in dir(display): if not monitor:
if self.monitor == None or self.monitor < 0: monitor = self.get_display().get_monitor(0)
monitor = display.get_monitor(0) if monitor:
else: geometry = monitor.get_geometry()
monitor = display.get_monitor(self.monitor) return (geometry.x, geometry.y, geometry.width, geometry.height)
if monitor: log.error("No monitor found! This is going to go badly")
geometry = monitor.get_geometry() return (0, 0, 1920, 1080)
return (geometry.x, geometry.y, geometry.width, geometry.height)
log.warn("No monitor found! This is going to go badly")
return (0, 0, 1920, 1080) # We're in trouble
def get_floating_coords(self): def get_floating_coords(self):
(screen_x, screen_y, screen_width, screen_height) = self.get_display_coords() (screen_x, screen_y, screen_width, screen_height) = self.get_display_coords()
@ -323,7 +320,7 @@ class OverlayWindow(Gtk.Window):
return (screen_x + self.pos_x * screen_width, screen_y + self.pos_y * screen_height, self.width * screen_width, self.height * screen_height) return (screen_x + self.pos_x * screen_width, screen_y + self.pos_y * screen_height, self.width * screen_width, self.height * screen_height)
return (self.pos_x * screen_width, self.pos_y * screen_height, self.width * screen_width, self.height * screen_height) return (self.pos_x * screen_width, self.pos_y * screen_height, self.width * screen_width, self.height * screen_height)
else: else:
return (0, 0, screen_width, screen_height) return (screen_x, screen_y, screen_width, screen_height)
def set_needs_redraw(self, be_pushy=False): def set_needs_redraw(self, be_pushy=False):
if (not self.hidden and self.enabled) or be_pushy: if (not self.hidden and self.enabled) or be_pushy:
@ -374,26 +371,37 @@ class OverlayWindow(Gtk.Window):
""" """
Set the monitor this overlay should display on. Set the monitor this overlay should display on.
""" """
if type(idx) is str: plug_name = "%s" % (idx)
idx = 0 if self.monitor != plug_name:
if self.monitor != idx: self.monitor = plug_name
self.monitor = idx
if self.is_wayland: if self.is_wayland:
display = Gdk.Display.get_default() monitor = self.get_monitor_from_plug()
if "get_monitor" in dir(display): if monitor:
monitor = display.get_monitor(self.monitor) GtkLayerShell.set_monitor(self, monitor)
if monitor:
GtkLayerShell.set_monitor(self, monitor)
else:
self.hide()
self.set_wayland_state()
self.show()
else: else:
log.error("No get_monitor in display") self.hide()
self.set_wayland_state()
self.show()
self.set_untouchable() self.set_untouchable()
self.force_location() self.force_location()
self.set_needs_redraw() self.set_needs_redraw()
def get_monitor_from_plug(self):
if not self.monitor or self.monitor == "Any":
return None
display = Gdk.Display.get_default()
if not "get_n_monitors" in dir(display) or not "get_monitor" in dir(display):
return None
screen = self.get_screen()
count_monitors = display.get_n_monitors()
if count_monitors >= 1:
for i in range(0, count_monitors):
this_mon = display.get_monitor(i)
connector = screen.get_monitor_plug_name(i)
if connector == self.monitor:
return this_mon
return None
def set_align_x(self, align_right): def set_align_x(self, align_right):
""" """
Set the alignment (True for right, False for left) Set the alignment (True for right, False for left)

View file

@ -339,13 +339,20 @@ class MainSettingsWindow():
m.append_text("Any") m.append_text("Any")
display = Gdk.Display.get_default() display = Gdk.Display.get_default()
screen = self.window.get_screen()
if "get_n_monitors" in dir(display): if "get_n_monitors" in dir(display):
count_monitors = display.get_n_monitors() count_monitors = display.get_n_monitors()
if count_monitors >= 1: if count_monitors >= 1:
for i in range(0, count_monitors): for i in range(0, count_monitors):
v.append_text(display.get_monitor(i).get_model()) this_mon = display.get_monitor(i)
t.append_text(display.get_monitor(i).get_model()) manufacturer = this_mon.get_manufacturer()
m.append_text(display.get_monitor(i).get_model()) model = this_mon.get_model()
connector = screen.get_monitor_plug_name(i)
monitor_label = "%s %s\n%s" % (
manufacturer, model, connector)
v.append_text(monitor_label)
t.append_text(monitor_label)
m.append_text(monitor_label)
v.set_active(v_value) v.set_active(v_value)
t.set_active(t_value) t.set_active(t_value)
@ -421,20 +428,18 @@ class MainSettingsWindow():
self.widget['voice_anchor_float'].set_active( self.widget['voice_anchor_float'].set_active(
0 if config.getboolean("main", "floating", fallback=False) else 1) 0 if config.getboolean("main", "floating", fallback=False) else 1)
self.update_floating_ahchor() self.update_floating_anchor()
self.widget['voice_align_1'].set_active( self.widget['voice_align_1'].set_active(
config.getboolean("main", "rightalign", fallback=False)) config.getboolean("main", "rightalign", fallback=False))
self.widget['voice_align_2'].set_active( self.widget['voice_align_2'].set_active(
config.getint("main", "topalign", fallback=1)) config.getint("main", "topalign", fallback=1))
monitor = 0 self.widget['voice_monitor'].set_active(
try: self.get_monitor_index_from_plug(
config.getint("main", "monitor", fallback=0) config.get("main", "monitor", fallback="Any")
except: )
pass )
self.widget['voice_monitor'].set_active(monitor+1)
font = config.get("main", "font", fallback=None) font = config.get("main", "font", fallback=None)
if font: if font:
@ -600,13 +605,11 @@ class MainSettingsWindow():
self.widget['text_background_colour'].set_rgba(self.make_colour(config.get( self.widget['text_background_colour'].set_rgba(self.make_colour(config.get(
"text", "bg_col", fallback="[0.0,0.0,0.0,0.5]"))) "text", "bg_col", fallback="[0.0,0.0,0.0,0.5]")))
monitor = 0 self.widget['text_monitor'].set_active(
try: self.get_monitor_index_from_plug(
config.getint("text", "monitor", fallback=0) config.get("text", "monitor", fallback="Any")
except: )
pass )
self.widget['text_monitor'].set_active(monitor+1)
self.widget['text_show_attachments'].set_active(config.getboolean( self.widget['text_show_attachments'].set_active(config.getboolean(
"text", "show_attach", fallback=True)) "text", "show_attach", fallback=True))
@ -643,13 +646,11 @@ class MainSettingsWindow():
self.widget['notification_background_colour'].set_rgba(self.make_colour(config.get( self.widget['notification_background_colour'].set_rgba(self.make_colour(config.get(
"notification", "bg_col", fallback="[0.0,0.0,0.0,0.5]"))) "notification", "bg_col", fallback="[0.0,0.0,0.0,0.5]")))
monitor = 0 self.widget['notification_monitor'].set_active(
try: self.get_monitor_index_from_plug(
config.getint("notification", "monitor", fallback=0) config.get("notification", "monitor", fallback="Any")
except: )
pass )
self.widget['notification_monitor'].set_active(monitor+1)
self.widget['notification_align_1'].set_active(config.getboolean( self.widget['notification_align_1'].set_active(config.getboolean(
"notification", "rightalign", fallback=True)) "notification", "rightalign", fallback=True))
@ -730,6 +731,20 @@ class MainSettingsWindow():
guild_ids.append(guild_id) guild_ids.append(guild_id)
return guild_ids return guild_ids
def get_monitor_index_from_plug(self, monitor):
if not monitor or monitor == "Any":
return 0
display = Gdk.Display.get_default()
screen = self.window.get_screen()
if "get_n_monitors" in dir(display):
count_monitors = display.get_n_monitors()
if count_monitors >= 1:
for i in range(0, count_monitors):
connector = screen.get_monitor_plug_name(i)
if connector == monitor:
return i+1
return 0
def get_monitor_obj(self, idx): def get_monitor_obj(self, idx):
""" """
Helper function to find the monitor object of the monitor Helper function to find the monitor object of the monitor
@ -828,13 +843,6 @@ class MainSettingsWindow():
with open(self.rpc_file, 'w') as f: with open(self.rpc_file, 'w') as f:
f.write('--rpc --close') f.write('--rpc --close')
def voice_toggle_test_content(self, button):
self.voice_overlay.set_show_dummy(button.get_active())
self.show_dummy = button.get_active()
if self.show_dummy:
self.voice_overlay.set_enabled(True)
self.voice_overlay.set_hidden(False)
def overview_close(self, button): def overview_close(self, button):
log.info("Quit pressed") log.info("Quit pressed")
self.close_overlay() self.close_overlay()
@ -968,9 +976,9 @@ class MainSettingsWindow():
def voice_anchor_float_changed(self, button): def voice_anchor_float_changed(self, button):
self.config_set("main", "floating", "%s" % (button.get_active() == 0)) self.config_set("main", "floating", "%s" % (button.get_active() == 0))
self.update_floating_ahchor() self.update_floating_anchor()
def update_floating_ahchor(self): def update_floating_anchor(self):
floating = self.widget['voice_anchor_float'].get_active() == 0 floating = self.widget['voice_anchor_float'].get_active() == 0
if 'XDG_SESSION_DESKTOP' in os.environ and os.environ['XDG_SESSION_DESKTOP'] == 'cinnamon': if 'XDG_SESSION_DESKTOP' in os.environ and os.environ['XDG_SESSION_DESKTOP'] == 'cinnamon':
floating = True floating = True
@ -985,7 +993,14 @@ class MainSettingsWindow():
self.widget['voice_place_window_button'].hide() self.widget['voice_place_window_button'].hide()
def voice_monitor_changed(self, button): def voice_monitor_changed(self, button):
self.config_set("main", "monitor", "%s" % (button.get_active()-1)) screen = self.window.get_screen()
idx = button.get_active()
plug = "Any"
if idx > 0:
monitor = screen.get_monitor_plug_name(button.get_active()-1)
if monitor:
plug = monitor
self.config_set("main", "monitor", plug)
def voice_align_1_changed(self, button): def voice_align_1_changed(self, button):
self.config_set("main", "rightalign", "%s" % (button.get_active())) self.config_set("main", "rightalign", "%s" % (button.get_active()))
@ -1202,7 +1217,12 @@ class MainSettingsWindow():
self.config_set("text", "bg_col", json.dumps(colour)) self.config_set("text", "bg_col", json.dumps(colour))
def text_monitor_changed(self, button): def text_monitor_changed(self, button):
self.config_set("text", "monitor", "%s" % (button.get_active()-1)) screen = self.window.get_screen()
plug = "Any"
monitor = screen.get_monitor_plug_name(button.get_active()-1)
if monitor:
plug = monitor
self.config_set("text", "monitor", plug)
def text_show_attachments_changed(self, button): def text_show_attachments_changed(self, button):
self.config_set("text", "show_attach", "%s" % (button.get_active())) self.config_set("text", "show_attach", "%s" % (button.get_active()))
@ -1239,8 +1259,12 @@ class MainSettingsWindow():
self.config_set("notification", "bg_col", json.dumps(colour)) self.config_set("notification", "bg_col", json.dumps(colour))
def notification_monitor_changed(self, button): def notification_monitor_changed(self, button):
self.config_set("notification", "monitor", "%s" % screen = self.window.get_screen()
(button.get_active()-1)) plug = "Any"
monitor = screen.get_monitor_plug_name(button.get_active()-1)
if monitor:
plug = monitor
self.config_set("notification", "monitor", plug)
def notification_align_1_changed(self, button): def notification_align_1_changed(self, button):
self.config_set("notification", "rightalign", "%s" % self.config_set("notification", "rightalign", "%s" %