From 12e2e2101ac4642c8ae5cd6e78649a6061de18a6 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Mon, 12 Feb 2024 06:27:04 +1100 Subject: [PATCH] fix screens --- v3/pkg/application/linux_cgo.go | 50 +++++++++++++++++++++- v3/pkg/application/screen_linux.go | 12 +++++- v3/pkg/application/webview_window_linux.go | 16 ------- 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/v3/pkg/application/linux_cgo.go b/v3/pkg/application/linux_cgo.go index 5d0c73fca..8f2606dbc 100644 --- a/v3/pkg/application/linux_cgo.go +++ b/v3/pkg/application/linux_cgo.go @@ -618,9 +618,10 @@ func getScreenByIndex(display *C.struct__GdkDisplay, index int) *Screen { if C.gdk_monitor_is_primary(monitor) == 1 { primary = true } + name := C.gdk_monitor_get_model(monitor) return &Screen{ ID: fmt.Sprintf("%d", index), - Name: fmt.Sprintf("Screen %d", index), + Name: C.GoString(name), IsPrimary: primary, Scale: float32(C.gdk_monitor_get_scale_factor(monitor)), X: int(geometry.x), @@ -733,6 +734,25 @@ func (w *linuxWebviewWindow) getCurrentMonitor() *C.GdkMonitor { return C.gdk_display_get_monitor_at_window(display, gdkWindow) } +func (w *linuxWebviewWindow) getScreen() (*Screen, error) { + // Get the current screen for the window + monitor := w.getCurrentMonitor() + name := C.gdk_monitor_get_model(monitor) + mx, my, width, height, scale := w.getCurrentMonitorGeometry() + return &Screen{ + ID: fmt.Sprintf("%d", w.id), // A unique identifier for the display + Name: C.GoString(name), // The name of the display + Scale: float32(scale), // The scale factor of the display + X: mx, // The x-coordinate of the top-left corner of the rectangle + Y: my, // The y-coordinate of the top-left corner of the rectangle + Size: Size{Width: width, Height: height}, // The size of the display + Bounds: Rect{}, // The bounds of the display + WorkArea: Rect{}, // The work area of the display + IsPrimary: false, // Whether this is the primary display + Rotation: 0.0, // The rotation of the display + }, nil +} + func (w *linuxWebviewWindow) getCurrentMonitorGeometry() (x int, y int, width int, height int, scale int) { monitor := w.getCurrentMonitor() if monitor == nil { @@ -929,6 +949,34 @@ func (w *linuxWebviewWindow) setBackgroundColour(colour RGBA) { C.free(unsafe.Pointer(cssStr)) } +func getPrimaryScreen() (*Screen, error) { + display := C.gdk_display_get_default() + monitor := C.gdk_display_get_primary_monitor(display) + geometry := C.GdkRectangle{} + C.gdk_monitor_get_geometry(monitor, &geometry) + scale := int(C.gdk_monitor_get_scale_factor(monitor)) + // get the name for the screen + name := C.gdk_monitor_get_model(monitor) + return &Screen{ + ID: "0", + Name: C.GoString(name), + IsPrimary: true, + X: int(geometry.x), + Y: int(geometry.y), + Size: Size{ + Height: int(geometry.height), + Width: int(geometry.width), + }, + Bounds: Rect{ + X: int(geometry.x), + Y: int(geometry.y), + Height: int(geometry.height), + Width: int(geometry.width), + }, + Scale: float32(scale), + }, nil +} + func windowSetGeometryHints(window pointer, minWidth, minHeight, maxWidth, maxHeight int) { size := C.GdkGeometry{ min_width: C.int(minWidth), diff --git a/v3/pkg/application/screen_linux.go b/v3/pkg/application/screen_linux.go index d93cfbd92..f6dfdf59d 100644 --- a/v3/pkg/application/screen_linux.go +++ b/v3/pkg/application/screen_linux.go @@ -3,12 +3,20 @@ package application import ( - "fmt" "sync" ) func (a *linuxApp) getPrimaryScreen() (*Screen, error) { - return nil, fmt.Errorf("not implemented") + var wg sync.WaitGroup + var screen *Screen + var err error + wg.Add(1) + InvokeSync(func() { + screen, err = getPrimaryScreen() + wg.Done() + }) + wg.Wait() + return screen, err } func (a *linuxApp) getScreens() ([]*Screen, error) { diff --git a/v3/pkg/application/webview_window_linux.go b/v3/pkg/application/webview_window_linux.go index 38b6f71fd..448d383fb 100644 --- a/v3/pkg/application/webview_window_linux.go +++ b/v3/pkg/application/webview_window_linux.go @@ -70,22 +70,6 @@ func (w *linuxWebviewWindow) openContextMenu(menu *Menu, data *ContextMenuData) w.contextMenuShow(native, data) } -func (w *linuxWebviewWindow) getScreen() (*Screen, error) { - mx, my, width, height, scale := w.getCurrentMonitorGeometry() - return &Screen{ - ID: fmt.Sprintf("%d", w.id), // A unique identifier for the display - Name: w.parent.Name(), // The name of the display - Scale: float32(scale), // The scale factor of the display - X: mx, // The x-coordinate of the top-left corner of the rectangle - Y: my, // The y-coordinate of the top-left corner of the rectangle - Size: Size{Width: width, Height: height}, // The size of the display - Bounds: Rect{}, // The bounds of the display - WorkArea: Rect{}, // The work area of the display - IsPrimary: false, // Whether this is the primary display - Rotation: 0.0, // The rotation of the display - }, nil -} - func (w *linuxWebviewWindow) focus() { w.present() }