I'm about to create a desktop based widget application using python via the gi.repository and the Gtk/Gdk v3.0. The goal is to have the window taking the whole screen being transparent, frameless and not accepting any focus. In addition it should be shown in every workspace and kept bellow any other window. After spending a long time I figured it out with the following code, yet with a drawback, the window has a vertical white line to the right side (kind of a border). So is there any solution to get rid of this line?
Os: Ubuntu 18.04 Python: 3.6
ui.py
import screeninfo
import gi
try:
gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0")
gi.require_foreign("cairo")
except ImportError:
print("No Gtk v3.0 or pycairo integration")
from gi.repository import Gtk, Gdk, GLib
class Window (Gtk.Window):
def __init__ (self, canvas):
Gtk.Window.__init__(self)
self.set_skip_pager_hint(True)
self.set_skip_taskbar_hint(True)
self.set_type_hint(Gdk.WindowTypeHint.DESKTOP)
self.set_decorated(False)
self.set_keep_below(True)
self.set_accept_focus(False)
self.set_can_focus(False)
width = 500
height = 500
for monitor in screeninfo.get_monitors():
if monitor.is_primary:
width = monitor.width
height = monitor.height
# Todo: remove the annoying white border line on the right
self.set_size_request(width, height)
#Set transparency
screen = self.get_screen()
rgba = screen.get_rgba_visual()
self.set_visual(rgba)
self.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(0, 0, 0, 0))
drawingarea = Gtk.DrawingArea()
self.add(drawingarea)
drawingarea.connect('draw', canvas.draw)
self.connect('destroy', Gtk.main_quit)
self.show_all()
self.move(0, 0)
def launch (self):
GLib.timeout_add_seconds(1, self.refresh)
Gtk.main()
return True
def refresh (self):
self.queue_draw()
return True
canvas.py
import cairo
FONT = 'UbuntuCondensent'
SLANT = cairo.FONT_SLANT_NORMAL
BOLD = cairo.FONT_WEIGHT_NORMAL
def draw (da, ctx):
ctx.set_source_rgb(1, 1, 1)
ctx.select_font_face(FONT, SLANT, BOLD)
ctx.set_font_size(32)
ctx.move_to(100, 100)
ctx.text_path('Hi There!')
ctx.fill()
main.py
import signal
import ui
import canvas
def main ():
signal.signal(signal.SIGINT, signal.SIG_DFL)
win = ui.Window(canvas)
win.launch()
if __name__ == '__main__':
main()