rework window size workaround
This commit is contained in:
@@ -54,4 +54,4 @@ require (
|
|||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
replace fyne.io/fyne/v2 v2.5.0 => github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240805144743-24df77c3cc7e
|
replace fyne.io/fyne/v2 v2.5.0 => github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240807180232-d2b0dad0b17d
|
||||||
|
|||||||
@@ -81,8 +81,8 @@ github.com/dweymouth/fyne-lyrics v0.0.0-20240528234907-15eee7ce5e64 h1:RUIrnGY03
|
|||||||
github.com/dweymouth/fyne-lyrics v0.0.0-20240528234907-15eee7ce5e64/go.mod h1:3YrjFDHMlhCsSZ/OvmJCxWm9QHSgOVWZBxnraZz9Z7c=
|
github.com/dweymouth/fyne-lyrics v0.0.0-20240528234907-15eee7ce5e64/go.mod h1:3YrjFDHMlhCsSZ/OvmJCxWm9QHSgOVWZBxnraZz9Z7c=
|
||||||
github.com/dweymouth/fyne-tooltip v0.2.0 h1:6Zy3gryctuPoQfYf8Xp3tjenioebMt11NBGW/QXIvxE=
|
github.com/dweymouth/fyne-tooltip v0.2.0 h1:6Zy3gryctuPoQfYf8Xp3tjenioebMt11NBGW/QXIvxE=
|
||||||
github.com/dweymouth/fyne-tooltip v0.2.0/go.mod h1:zEgy7p9tSVIuy2GufFbOCoK3Q04zhyDPOotlU4G3Ma4=
|
github.com/dweymouth/fyne-tooltip v0.2.0/go.mod h1:zEgy7p9tSVIuy2GufFbOCoK3Q04zhyDPOotlU4G3Ma4=
|
||||||
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240805144743-24df77c3cc7e h1:FSTLNY9xV0+4/x9jKPXqUpwPZfhkAMz5ZnzLBkRirMw=
|
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240807180232-d2b0dad0b17d h1:A8HSVm7wn1aEMdT/8YPtuP5XGwasqZ5kxcdBhIfxXvU=
|
||||||
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240805144743-24df77c3cc7e/go.mod h1:9D4oT3NWeG+MLi/lP7ItZZyujHC/qqMJpoGTAYX5Uqc=
|
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240807180232-d2b0dad0b17d/go.mod h1:9D4oT3NWeG+MLi/lP7ItZZyujHC/qqMJpoGTAYX5Uqc=
|
||||||
github.com/dweymouth/go-jellyfin v0.0.0-20240517151952-5ceca61cb645 h1:KzqSaQwG3HsTZQlEtkp0BeUy9vmYZ0rq0B15qIPSiBs=
|
github.com/dweymouth/go-jellyfin v0.0.0-20240517151952-5ceca61cb645 h1:KzqSaQwG3HsTZQlEtkp0BeUy9vmYZ0rq0B15qIPSiBs=
|
||||||
github.com/dweymouth/go-jellyfin v0.0.0-20240517151952-5ceca61cb645/go.mod h1:fcUagHBaQnt06GmBAllNE0J4O/7064zXRWdqnTTtVjI=
|
github.com/dweymouth/go-jellyfin v0.0.0-20240517151952-5ceca61cb645/go.mod h1:fcUagHBaQnt06GmBAllNE0J4O/7064zXRWdqnTTtVjI=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
|
|||||||
@@ -5,14 +5,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/dweymouth/supersonic/backend"
|
"github.com/dweymouth/supersonic/backend"
|
||||||
"github.com/dweymouth/supersonic/res"
|
"github.com/dweymouth/supersonic/res"
|
||||||
"github.com/dweymouth/supersonic/ui"
|
"github.com/dweymouth/supersonic/ui"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
"fyne.io/fyne/v2/lang"
|
"fyne.io/fyne/v2/lang"
|
||||||
)
|
)
|
||||||
@@ -59,39 +57,22 @@ func main() {
|
|||||||
} else {
|
} else {
|
||||||
mainWindow.Controller.DoConnectToServerWorkflow(defaultServer)
|
mainWindow.Controller.DoConnectToServerWorkflow(defaultServer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// hacky workaround for https://github.com/fyne-io/fyne/issues/4964
|
|
||||||
if runtime.GOOS == "linux" {
|
|
||||||
time.Sleep(350 * time.Millisecond)
|
|
||||||
canvas := mainWindow.Window.Canvas()
|
|
||||||
size := canvas.Size()
|
|
||||||
desired := mainWindow.DesiredSize()
|
|
||||||
if !inDelta(size, desired, 1) {
|
|
||||||
// window drawn at incorrect size on startup
|
|
||||||
scale := canvas.Scale()
|
|
||||||
for i := 0; i < 3 && !inDelta(size, desired, 1); i++ {
|
|
||||||
if i > 0 {
|
|
||||||
// if resize didn't work the first time, try again with slightly
|
|
||||||
// different desired size
|
|
||||||
desired.Subtract(fyne.NewSize(2, 2))
|
|
||||||
}
|
|
||||||
SendResizeToPID(os.Getpid(), int(desired.Width*scale), int(desired.Height*scale))
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
size = canvas.Size()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// slightly hacky workaround for https://github.com/fyne-io/fyne/issues/4964
|
||||||
|
workaroundWindowSize := sync.OnceFunc(func() {
|
||||||
|
s := mainWindow.DesiredSize()
|
||||||
|
scale := mainWindow.Window.Canvas().Scale()
|
||||||
|
s.Width *= scale
|
||||||
|
s.Height *= scale
|
||||||
|
// exported in Supersonic Fyne fork
|
||||||
|
mainWindow.Window.ProcessResized(int(s.Width), int(s.Height))
|
||||||
|
})
|
||||||
|
fyneApp.Lifecycle().SetOnEnteredForeground(func() {
|
||||||
|
workaroundWindowSize()
|
||||||
|
})
|
||||||
mainWindow.ShowAndRun()
|
mainWindow.ShowAndRun()
|
||||||
|
|
||||||
log.Println("Running shutdown tasks...")
|
log.Println("Running shutdown tasks...")
|
||||||
myApp.Shutdown()
|
myApp.Shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
func inDelta(a, b fyne.Size, delta float32) bool {
|
|
||||||
diffW := a.Width - b.Width
|
|
||||||
diffH := a.Height - b.Height
|
|
||||||
return diffW < delta && diffW > -delta &&
|
|
||||||
diffH < delta && diffH > -delta
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
//go:build linux && !wayland
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <X11/Xlib.h>
|
|
||||||
#include <X11/Xatom.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "xresize.h"
|
|
||||||
|
|
||||||
// thanks ChatGPT ;)
|
|
||||||
int find_windows_by_pid(Display *display, Window root, pid_t pid, Window* out, int n) {
|
|
||||||
Window *children;
|
|
||||||
unsigned int nchildren;
|
|
||||||
if (!XQueryTree(display, root, &root, &root, &children, &nchildren)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < nchildren; i++) {
|
|
||||||
Atom pidAtom = XInternAtom(display, "_NET_WM_PID", True);
|
|
||||||
if (pidAtom != None) {
|
|
||||||
Atom type;
|
|
||||||
int format;
|
|
||||||
unsigned long nitems, bytes_after;
|
|
||||||
unsigned char *prop_pid = NULL;
|
|
||||||
|
|
||||||
if (XGetWindowProperty(display, children[i], pidAtom, 0, 1, False, XA_CARDINAL,
|
|
||||||
&type, &format, &nitems, &bytes_after, &prop_pid) == Success && prop_pid) {
|
|
||||||
if (pid == *((pid_t *)prop_pid)) {
|
|
||||||
out[n++] = children[i];
|
|
||||||
}
|
|
||||||
XFree(prop_pid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
n = find_windows_by_pid(display, children[i], pid, out, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
XFree(children);
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
void send_resize_event(Display *display, Window window, int width, int height) {
|
|
||||||
XResizeWindow(display, window, width, height);
|
|
||||||
XFlush(display);
|
|
||||||
}
|
|
||||||
|
|
||||||
int send_resize_to_pid(int pid, int w, int h) {
|
|
||||||
Display *display = XOpenDisplay(NULL);
|
|
||||||
if (!display) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
int ret = 0;
|
|
||||||
Window windows[128];
|
|
||||||
Window root = DefaultRootWindow(display);
|
|
||||||
|
|
||||||
int n = find_windows_by_pid(display, root, pid, &windows[0], 0);
|
|
||||||
if (n > 0) {
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
send_resize_event(display, windows[i], w, h);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
XCloseDisplay(display);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
//go:build linux && !wayland
|
|
||||||
|
|
||||||
int send_resize_to_pid(int pid, int w, int h);
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
//go:build !linux || wayland
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
func SendResizeToPID(pid, w, h int) {}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
//go:build linux && !wayland
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo LDFLAGS: -lX11
|
|
||||||
#include "xresize.h"
|
|
||||||
*/
|
|
||||||
import (
|
|
||||||
"C"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SendResizeToPID(pid, w, h int) {
|
|
||||||
C.send_resize_to_pid(C.int(pid), C.int(w), C.int(h))
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user