Last active
January 31, 2021 03:20
-
-
Save Miqueas/486921cfb6e7bdf82a7da3b3d3bf05fe to your computer and use it in GitHub Desktop.
[Lua + Gtk 3] Switches between enabling/disabling the CSD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local lgi = require("lgi") | |
local Gtk = lgi.Gtk | |
local GObject = lgi.GObject | |
local Example = lgi.package("Example") | |
Example:class("App", Gtk.Application) | |
Example:class("Header", Gtk.HeaderBar) | |
Example:class("Window", Gtk.ApplicationWindow) | |
function Example.App:_init( ... ) | |
self.application_id = "org.example.Gtk" | |
end | |
function Example.App:do_startup( ... ) | |
self._parent.do_startup(self) | |
end | |
function Example.App:do_activate( ... ) | |
local Window = Example.Window({ title = "CSD Disabled" }) | |
local Btn = Gtk.Button({ | |
label = "Toggle CSD", | |
visible = true, | |
expand = false, | |
halign = Gtk.Align.CENTER, | |
valign = Gtk.Align.CENTER | |
}) | |
local App = self | |
function ToggleCSD(self) | |
App:hold() | |
App:remove_window(Window) | |
Window:destroy() | |
if Window.has_csd then | |
Window = Example.Window({ title = "CSD Disabled" }) | |
Window.has_csd = false | |
else | |
Window = Example.Window() | |
Window:set_titlebar(Example.Header({ title = "CSD Enabled" })) | |
Window.has_csd = true | |
end | |
Window:add(Gtk.Button({ | |
label = "Toggle CSD", | |
visible = true, | |
expand = false, | |
halign = Gtk.Align.CENTER, | |
valign = Gtk.Align.CENTER, | |
on_clicked = ToggleCSD | |
})) | |
Window:present() | |
App:add_window(Window) | |
App:release() | |
end | |
Btn.on_clicked = ToggleCSD | |
Window:add(Btn) | |
Window:present() | |
self:add_window(Window) | |
end | |
function Example.Header:_init( ... ) | |
self.decoration_layout = ":close" | |
self.show_close_button = true | |
self.visible = true | |
self.id = "header" | |
end | |
function Example.Window:_class_init(Class) | |
function Class:set_property(id, value, pspec) | |
if id == 1 then | |
self.priv.has_csd = value:get_boolean() | |
else | |
GObject.OBJECT_WARN_INVALID_PROPERTY_ID(self, id, pspec) | |
end | |
end | |
function Class:get_property(id, value, pspec) | |
if id == 1 then | |
value:set_boolean(self.priv.has_csd) | |
else | |
GObject.OBJECT_WARN_INVALID_PROPERTY_ID(self, id, pspec) | |
end | |
end | |
Class:install_property(1, GObject.ParamSpecBoolean( | |
"has-csd", | |
"Has CSD", | |
"Holds the CSD status (enabled/disabled) of the window", | |
false, | |
{ "READWRITE" } | |
)) | |
end | |
function Example.Window:_init( ... ) | |
self.window_position = Gtk.WindowPosition.CENTER | |
self.width_request = 600 | |
self.height_request = 400 | |
self.border_width = 80 | |
self.title = "CSD Disabled" | |
end | |
return Example.App():run(arg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment