├── .gitignore ├── LICENSE ├── README.md ├── example ├── example.go ├── go.mod ├── go.sum └── layershell └── layer.go /.gitignore: -------------------------------------------------------------------------------- 1 | /gotk3-layershell 2 | .idea/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Dan Lasky 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gotk3-layershell 2 | 3 | A simple golang library to provide bindings for the excellent [Gtk Layer Shell](https://github.com/wmww/gtk-layer-shell) library which can be consumed in the also excellent [gotk3 gtk library](https://github.com/gotk3/gotk3). 4 | 5 | This allows for GTK windows in linux window managers like swaywm that utilize the Layer Shell proticol in wayland to be positioned relative to the viewport including pinning and layer depth control. 6 | 7 | ## Getting started 8 | 9 | For the moment please see `example.go` for a simple working example 10 | 11 | ## WIP 12 | 13 | While the critical API components are ported (layer, anchors), currently the entirety `gtk_layer_shell.h` is only supported up to pre .5 versions of layer-shell. -------------------------------------------------------------------------------- /example: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dlasky/gotk3-layershell/5c5115f0d77479c452ef686e3d7f327f2a341b3c/example -------------------------------------------------------------------------------- /example.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/dlasky/gotk3-layershell/layershell" 5 | "github.com/gotk3/gotk3/gtk" 6 | "log" 7 | ) 8 | 9 | func main() { 10 | // Initialize GTK without parsing any command line arguments. 11 | gtk.Init(nil) 12 | 13 | // Create a new toplevel window, set its title, and connect it to the 14 | // "destroy" signal to exit the GTK main loop when it is destroyed. 15 | win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL) 16 | if err != nil { 17 | log.Fatal("Unable to create window:", err) 18 | } 19 | layershell.InitForWindow(win) 20 | layershell.SetNamespace(win, "gtk-layer-shell") 21 | 22 | layershell.SetAnchor(win, layershell.LAYER_SHELL_EDGE_LEFT,true); 23 | layershell.SetAnchor(win, layershell.LAYER_SHELL_EDGE_TOP, true); 24 | layershell.SetAnchor(win, layershell.LAYER_SHELL_EDGE_RIGHT,true); 25 | 26 | layershell.SetLayer(win, layershell.LAYER_SHELL_LAYER_BOTTOM) 27 | layershell.SetMargin(win, layershell.LAYER_SHELL_EDGE_TOP, 0) 28 | layershell.SetMargin(win, layershell.LAYER_SHELL_EDGE_LEFT, 0) 29 | layershell.SetMargin(win, layershell.LAYER_SHELL_EDGE_RIGHT,0) 30 | 31 | layershell.SetExclusiveZone(win, 200) 32 | 33 | 34 | win.SetTitle("Simple Example") 35 | win.Connect("destroy", func() { 36 | gtk.MainQuit() 37 | }) 38 | 39 | // Create a new label widget to show in the window. 40 | l, err := gtk.LabelNew("Hello, gotk3!") 41 | if err != nil { 42 | log.Fatal("Unable to create label:", err) 43 | } 44 | 45 | // Add the label to the window. 46 | win.Add(l) 47 | 48 | // Set the default window size. 49 | win.SetDefaultSize(800, 30) 50 | 51 | // Recursively show all widgets contained in this window. 52 | win.ShowAll() 53 | 54 | // Begin executing the GTK main loop. This blocks until 55 | // gtk.MainQuit() is run. 56 | gtk.Main() 57 | } 58 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/dlasky/gotk3-layershell 2 | 3 | go 1.15 4 | 5 | require github.com/gotk3/gotk3 v0.6.1 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/gotk3/gotk3 v0.6.1 h1:GJ400a0ecEEWrzjBvzBzH+pB/esEMIGdB9zPSmBdoeo= 2 | github.com/gotk3/gotk3 v0.6.1/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q= 3 | -------------------------------------------------------------------------------- /layershell/layer.go: -------------------------------------------------------------------------------- 1 | package layershell 2 | 3 | // #cgo pkg-config: gtk+-3.0 gtk-layer-shell-0 4 | // #include 5 | // #include "gtk-layer-shell.h" 6 | import "C" 7 | import ( 8 | "github.com/gotk3/gotk3/gdk" 9 | "github.com/gotk3/gotk3/gtk" 10 | "unsafe" 11 | ) 12 | 13 | type LayerShellEdgeFlags int 14 | 15 | const ( 16 | LAYER_SHELL_EDGE_LEFT LayerShellEdgeFlags = iota 17 | LAYER_SHELL_EDGE_RIGHT 18 | LAYER_SHELL_EDGE_TOP 19 | LAYER_SHELL_EDGE_BOTTOM 20 | ) 21 | 22 | type LayerShellLayerFlags int 23 | 24 | const ( 25 | LAYER_SHELL_LAYER_BACKGROUND LayerShellLayerFlags = iota 26 | LAYER_SHELL_LAYER_BOTTOM 27 | LAYER_SHELL_LAYER_TOP 28 | LAYER_SHELL_LAYER_OVERLAY 29 | ) 30 | 31 | type LayerShellKeyboardMode int 32 | 33 | const ( 34 | LAYER_SHELL_KEYBOARD_MODE_NONE LayerShellKeyboardMode= iota 35 | LAYER_SHELL_KEYBOARD_MODE_EXCLUSIVE 36 | LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND 37 | LAYER_SHELL_KEYBOARD_MODE_ENTRY_NUMBER 38 | ) 39 | 40 | func nativeWindow(window *gtk.Window) *C.GtkWindow { 41 | w := window.Native() 42 | wp := (*C.GtkWindow)(unsafe.Pointer(w)) 43 | return wp; 44 | } 45 | 46 | func nativeMonitor(monitor *gdk.Monitor) *C.GdkMonitor { 47 | m := monitor.Native() 48 | mp := (*C.GdkMonitor)(unsafe.Pointer(m)) 49 | return mp; 50 | } 51 | 52 | func boolConv(b bool) C.int { 53 | if (b) { return C.int(1)} 54 | return C.int(0) 55 | } 56 | 57 | func InitForWindow(window *gtk.Window) { 58 | w := nativeWindow(window); 59 | C.gtk_layer_init_for_window(w) 60 | } 61 | 62 | func SetLayer(window *gtk.Window, layer LayerShellLayerFlags) { 63 | w := nativeWindow(window) 64 | C.gtk_layer_set_layer(w, C.GtkLayerShellLayer(layer)) 65 | } 66 | 67 | func SetNamespace(window *gtk.Window, name string) { 68 | w := nativeWindow(window) 69 | cName := C.CString(name) 70 | C.gtk_layer_set_namespace(w, cName) 71 | C.free(unsafe.Pointer(cName)) 72 | } 73 | 74 | func AutoExclusiveZoneEnable(window *gtk.Window) { 75 | w := nativeWindow(window) 76 | C.gtk_layer_auto_exclusive_zone_enable(w) 77 | } 78 | 79 | func SetExclusiveZone(window *gtk.Window, size int) { 80 | w := nativeWindow(window) 81 | C.gtk_layer_set_exclusive_zone(w, C.int(size)) 82 | } 83 | 84 | func SetAnchor(window *gtk.Window, side LayerShellEdgeFlags, pinned bool) { 85 | w := nativeWindow(window) 86 | C.gtk_layer_set_anchor(w, C.GtkLayerShellEdge(side), boolConv(pinned)) 87 | } 88 | 89 | func SetMargin(window *gtk.Window, side LayerShellEdgeFlags, margin int) { 90 | w := nativeWindow(window) 91 | C.gtk_layer_set_margin(w, C.GtkLayerShellEdge(side), C.int(margin)) 92 | } 93 | 94 | func SetMonitor(window *gtk.Window, monitor *gdk.Monitor) { 95 | C.gtk_layer_set_monitor(nativeWindow(window), nativeMonitor(monitor)) 96 | } 97 | 98 | func SetKeyboardMode(window *gtk.Window, mode LayerShellKeyboardMode) { 99 | w := nativeWindow(window) 100 | C.gtk_layer_set_keyboard_mode(w, C.GtkLayerShellKeyboardMode(mode)) 101 | } 102 | --------------------------------------------------------------------------------