mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-20 19:09:29 +08:00
fix screens
This commit is contained in:
parent
e39097a17e
commit
12e2e2101a
@ -618,9 +618,10 @@ func getScreenByIndex(display *C.struct__GdkDisplay, index int) *Screen {
|
|||||||
if C.gdk_monitor_is_primary(monitor) == 1 {
|
if C.gdk_monitor_is_primary(monitor) == 1 {
|
||||||
primary = true
|
primary = true
|
||||||
}
|
}
|
||||||
|
name := C.gdk_monitor_get_model(monitor)
|
||||||
return &Screen{
|
return &Screen{
|
||||||
ID: fmt.Sprintf("%d", index),
|
ID: fmt.Sprintf("%d", index),
|
||||||
Name: fmt.Sprintf("Screen %d", index),
|
Name: C.GoString(name),
|
||||||
IsPrimary: primary,
|
IsPrimary: primary,
|
||||||
Scale: float32(C.gdk_monitor_get_scale_factor(monitor)),
|
Scale: float32(C.gdk_monitor_get_scale_factor(monitor)),
|
||||||
X: int(geometry.x),
|
X: int(geometry.x),
|
||||||
@ -733,6 +734,25 @@ func (w *linuxWebviewWindow) getCurrentMonitor() *C.GdkMonitor {
|
|||||||
return C.gdk_display_get_monitor_at_window(display, gdkWindow)
|
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) {
|
func (w *linuxWebviewWindow) getCurrentMonitorGeometry() (x int, y int, width int, height int, scale int) {
|
||||||
monitor := w.getCurrentMonitor()
|
monitor := w.getCurrentMonitor()
|
||||||
if monitor == nil {
|
if monitor == nil {
|
||||||
@ -929,6 +949,34 @@ func (w *linuxWebviewWindow) setBackgroundColour(colour RGBA) {
|
|||||||
C.free(unsafe.Pointer(cssStr))
|
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) {
|
func windowSetGeometryHints(window pointer, minWidth, minHeight, maxWidth, maxHeight int) {
|
||||||
size := C.GdkGeometry{
|
size := C.GdkGeometry{
|
||||||
min_width: C.int(minWidth),
|
min_width: C.int(minWidth),
|
||||||
|
@ -3,12 +3,20 @@
|
|||||||
package application
|
package application
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *linuxApp) getPrimaryScreen() (*Screen, error) {
|
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) {
|
func (a *linuxApp) getScreens() ([]*Screen, error) {
|
||||||
|
@ -70,22 +70,6 @@ func (w *linuxWebviewWindow) openContextMenu(menu *Menu, data *ContextMenuData)
|
|||||||
w.contextMenuShow(native, data)
|
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() {
|
func (w *linuxWebviewWindow) focus() {
|
||||||
w.present()
|
w.present()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user