109 lines
2.9 KiB
Python
109 lines
2.9 KiB
Python
import math
|
|
import sys
|
|
|
|
import gi
|
|
|
|
gi.require_version("Gtk", "3.0")
|
|
from gi.repository import Gtk # noqa
|
|
import cairo # noqa
|
|
from OpenGL.GL import glClearColor, glClear, glFlush, GL_COLOR_BUFFER_BIT
|
|
|
|
|
|
class TestWin(Gtk.Window):
|
|
WINDOW_POPUP = 1
|
|
|
|
def __init__(self):
|
|
Gtk.Window.__init__(self, type=self.WINDOW_POPUP)
|
|
|
|
self._default_monitor = 0
|
|
self.set_window_geometry()
|
|
|
|
self.layout = Gtk.Box()
|
|
self.layout.show()
|
|
self.add(self.layout)
|
|
|
|
self.gl = Gtk.GLArea()
|
|
self.gl.connect("render", self.gl_render)
|
|
self.gl.connect("realize", self.gl_realize)
|
|
# self.gl.connect('create-context', self.gl_context)
|
|
self.gl.show()
|
|
self.layout.pack_end(self.gl, True, True, 0)
|
|
|
|
self.make_rgba()
|
|
self.set_app_paintable(True)
|
|
self.connect("draw", self.on_draw)
|
|
|
|
self.show()
|
|
self.make_untouchable()
|
|
|
|
def make_rgba(self):
|
|
self.screen = self.get_screen()
|
|
self.visual = self.screen.get_rgba_visual()
|
|
if self.visual is None or not self.screen.is_composited():
|
|
print(
|
|
"WARNING: You do not appear to be running a composite manager"
|
|
", transparency not available"
|
|
)
|
|
else:
|
|
self.set_visual(self.visual)
|
|
|
|
def set_window_geometry(self):
|
|
geo = self.get_screen_size(self._default_monitor)
|
|
scale = (1.05, 6)
|
|
x, y, w, h = (
|
|
geo.x + geo.width / 2 - geo.width / scale[0] / 2,
|
|
geo.y,
|
|
geo.width / scale[0],
|
|
geo.height / scale[1],
|
|
)
|
|
self.move(x, y)
|
|
self.resize(w, h)
|
|
print(f"geometry: @{x:.0f},{y:.0f} {w:.0f}x{h:.0f}")
|
|
|
|
def get_screen_size(self, monitor):
|
|
return self.get_screen().get_monitor_geometry(monitor)
|
|
|
|
def on_draw(self, widget, cr):
|
|
# make everything transparent
|
|
cr.set_source_rgba(1.0, 1.0, 1.0, 0.1)
|
|
# cr.set_operator(cairo.OPERATOR_SOURCE)
|
|
cr.paint()
|
|
cr.set_operator(cairo.OPERATOR_OVER)
|
|
|
|
# draw the circle
|
|
w, h = self.get_size()
|
|
cr.translate(w / 2, h / 2)
|
|
cr.set_source_rgba(0.7, 0.3, 0.0, 0.6)
|
|
cr.arc(0, 0, 10, 0, 2 * math.pi)
|
|
cr.stroke_preserve()
|
|
cr.fill()
|
|
|
|
def make_untouchable(self):
|
|
self.input_shape_combine_region(cairo.Region(cairo.RectangleInt(0, 0, 0, 0)))
|
|
|
|
def gl_realize(self, gl_area):
|
|
error = gl_area.get_error()
|
|
if error != None:
|
|
print(f"ERROR: No OpenGL ({error})")
|
|
|
|
def gl_context(self, gl_area):
|
|
c = gl_area.get_context()
|
|
print(c, "context")
|
|
return c
|
|
|
|
def gl_render(self, area, context):
|
|
glClearColor(1.0, 0.5, 0.5, 1.0)
|
|
glClear(GL_COLOR_BUFFER_BIT)
|
|
glFlush()
|
|
print("rendering... done")
|
|
return True
|
|
|
|
def run(self):
|
|
Gtk.main()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = TestWin()
|
|
sys.exit(app.run())
|