mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 00:45:35 +00:00
app: replace Config.center with Perform(ActionCenter)
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -41,8 +41,6 @@ type Config struct {
|
|||||||
// CustomRenderer is true when the window content is rendered by the
|
// CustomRenderer is true when the window content is rendered by the
|
||||||
// client.
|
// client.
|
||||||
CustomRenderer bool
|
CustomRenderer bool
|
||||||
// center is a flag used to center the window. Set by option.
|
|
||||||
center bool
|
|
||||||
// Decorated reports whether window decorations are provided automatically.
|
// Decorated reports whether window decorations are provided automatically.
|
||||||
Decorated bool
|
Decorated bool
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-7
@@ -344,13 +344,6 @@ func (w *window) Configure(options []Option) {
|
|||||||
cnf.MaxSize = cnf.MaxSize.Div(int(screenScale))
|
cnf.MaxSize = cnf.MaxSize.Div(int(screenScale))
|
||||||
C.setMaxSize(w.window, C.CGFloat(cnf.MaxSize.X), C.CGFloat(cnf.MaxSize.Y))
|
C.setMaxSize(w.window, C.CGFloat(cnf.MaxSize.X), C.CGFloat(cnf.MaxSize.Y))
|
||||||
}
|
}
|
||||||
if cnf.center {
|
|
||||||
r := C.getScreenFrame(w.window) // the screen size of the window
|
|
||||||
sz := w.config.Size
|
|
||||||
x := (int(r.size.width) - sz.X) / 2
|
|
||||||
y := (int(r.size.height) - sz.Y) / 2
|
|
||||||
C.setScreenFrame(w.window, C.CGFloat(x), C.CGFloat(y), C.CGFloat(sz.X), C.CGFloat(sz.Y))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if cnf.Decorated != prev.Decorated {
|
if cnf.Decorated != prev.Decorated {
|
||||||
w.config.Decorated = cnf.Decorated
|
w.config.Decorated = cnf.Decorated
|
||||||
@@ -372,6 +365,12 @@ func (w *window) setTitle(prev, cnf Config) {
|
|||||||
func (w *window) Perform(acts system.Action) {
|
func (w *window) Perform(acts system.Action) {
|
||||||
walkActions(acts, func(a system.Action) {
|
walkActions(acts, func(a system.Action) {
|
||||||
switch a {
|
switch a {
|
||||||
|
case system.ActionCenter:
|
||||||
|
r := C.getScreenFrame(w.window) // the screen size of the window
|
||||||
|
sz := w.config.Size
|
||||||
|
x := (int(r.size.width) - sz.X) / 2
|
||||||
|
y := (int(r.size.height) - sz.Y) / 2
|
||||||
|
C.setScreenFrame(w.window, C.CGFloat(x), C.CGFloat(y), C.CGFloat(sz.X), C.CGFloat(sz.Y))
|
||||||
case system.ActionRaise:
|
case system.ActionRaise:
|
||||||
C.raiseWindow(w.window)
|
C.raiseWindow(w.window)
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-8
@@ -631,14 +631,6 @@ func (w *window) Configure(options []Option) {
|
|||||||
y := wr.Top
|
y := wr.Top
|
||||||
dx := r.Right - r.Left
|
dx := r.Right - r.Left
|
||||||
dy := r.Bottom - r.Top
|
dy := r.Bottom - r.Top
|
||||||
if w.config.center {
|
|
||||||
// Calculate center position on current monitor.
|
|
||||||
mi := windows.GetMonitorInfo(w.hwnd).Monitor
|
|
||||||
x = (mi.Right - mi.Left - dx) / 2
|
|
||||||
y = (mi.Bottom - mi.Top - dy) / 2
|
|
||||||
// Centering is done only once.
|
|
||||||
w.config.center = false
|
|
||||||
}
|
|
||||||
windows.SetWindowPos(w.hwnd, 0, x, y, dx, dy, windows.SWP_NOOWNERZORDER|windows.SWP_FRAMECHANGED)
|
windows.SetWindowPos(w.hwnd, 0, x, y, dx, dy, windows.SWP_NOOWNERZORDER|windows.SWP_FRAMECHANGED)
|
||||||
windows.ShowWindow(w.hwnd, windows.SW_SHOWNORMAL)
|
windows.ShowWindow(w.hwnd, windows.SW_SHOWNORMAL)
|
||||||
|
|
||||||
@@ -768,6 +760,18 @@ func (w *window) Close() {
|
|||||||
func (w *window) Perform(acts system.Action) {
|
func (w *window) Perform(acts system.Action) {
|
||||||
walkActions(acts, func(a system.Action) {
|
walkActions(acts, func(a system.Action) {
|
||||||
switch a {
|
switch a {
|
||||||
|
case system.ActionCenter:
|
||||||
|
if w.config.Mode != Windowed {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
r := windows.GetWindowRect(w.hwnd)
|
||||||
|
dx := r.Right - r.Left
|
||||||
|
dy := r.Bottom - r.Top
|
||||||
|
// Calculate center position on current monitor.
|
||||||
|
mi := windows.GetMonitorInfo(w.hwnd).Monitor
|
||||||
|
x := (mi.Right - mi.Left - dx) / 2
|
||||||
|
y := (mi.Bottom - mi.Top - dy) / 2
|
||||||
|
windows.SetWindowPos(w.hwnd, 0, x, y, dx, dy, windows.SWP_NOOWNERZORDER|windows.SWP_FRAMECHANGED)
|
||||||
case system.ActionRaise:
|
case system.ActionRaise:
|
||||||
w.raise()
|
w.raise()
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-16
@@ -230,22 +230,6 @@ func (w *x11Window) Configure(options []Option) {
|
|||||||
if shints.flags != 0 {
|
if shints.flags != 0 {
|
||||||
C.XSetWMNormalHints(w.x, w.xw, &shints)
|
C.XSetWMNormalHints(w.x, w.xw, &shints)
|
||||||
}
|
}
|
||||||
if cnf.center {
|
|
||||||
screen := C.XDefaultScreen(w.x)
|
|
||||||
width := C.XDisplayWidth(w.x, screen)
|
|
||||||
height := C.XDisplayHeight(w.x, screen)
|
|
||||||
|
|
||||||
var attrs C.XWindowAttributes
|
|
||||||
C.XGetWindowAttributes(w.x, w.xw, &attrs)
|
|
||||||
width -= attrs.border_width
|
|
||||||
height -= attrs.border_width
|
|
||||||
|
|
||||||
sz := w.config.Size
|
|
||||||
x := (int(width) - sz.X) / 2
|
|
||||||
y := (int(height) - sz.Y) / 2
|
|
||||||
|
|
||||||
C.XMoveResizeWindow(w.x, w.xw, C.int(x), C.int(y), C.uint(sz.X), C.uint(sz.Y))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if cnf.Decorated != prev.Decorated {
|
if cnf.Decorated != prev.Decorated {
|
||||||
w.config.Decorated = cnf.Decorated
|
w.config.Decorated = cnf.Decorated
|
||||||
@@ -276,12 +260,31 @@ func (w *x11Window) setTitle(prev, cnf Config) {
|
|||||||
func (w *x11Window) Perform(acts system.Action) {
|
func (w *x11Window) Perform(acts system.Action) {
|
||||||
walkActions(acts, func(a system.Action) {
|
walkActions(acts, func(a system.Action) {
|
||||||
switch a {
|
switch a {
|
||||||
|
case system.ActionCenter:
|
||||||
|
w.center()
|
||||||
case system.ActionRaise:
|
case system.ActionRaise:
|
||||||
w.raise()
|
w.raise()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *x11Window) center() {
|
||||||
|
screen := C.XDefaultScreen(w.x)
|
||||||
|
width := C.XDisplayWidth(w.x, screen)
|
||||||
|
height := C.XDisplayHeight(w.x, screen)
|
||||||
|
|
||||||
|
var attrs C.XWindowAttributes
|
||||||
|
C.XGetWindowAttributes(w.x, w.xw, &attrs)
|
||||||
|
width -= attrs.border_width
|
||||||
|
height -= attrs.border_width
|
||||||
|
|
||||||
|
sz := w.config.Size
|
||||||
|
x := (int(width) - sz.X) / 2
|
||||||
|
y := (int(height) - sz.Y) / 2
|
||||||
|
|
||||||
|
C.XMoveResizeWindow(w.x, w.xw, C.int(x), C.int(y), C.uint(sz.X), C.uint(sz.Y))
|
||||||
|
}
|
||||||
|
|
||||||
func (w *x11Window) raise() {
|
func (w *x11Window) raise() {
|
||||||
var xev C.XEvent
|
var xev C.XEvent
|
||||||
ev := (*C.XClientMessageEvent)(unsafe.Pointer(&xev))
|
ev := (*C.XClientMessageEvent)(unsafe.Pointer(&xev))
|
||||||
|
|||||||
@@ -989,12 +989,6 @@ func (w *Window) Perform(actions system.Action) {
|
|||||||
options = append(options, Maximized.Option())
|
options = append(options, Maximized.Option())
|
||||||
case system.ActionUnmaximize:
|
case system.ActionUnmaximize:
|
||||||
options = append(options, Windowed.Option())
|
options = append(options, Windowed.Option())
|
||||||
case system.ActionCenter:
|
|
||||||
options = append(options,
|
|
||||||
func(m unit.Metric, cnf *Config) {
|
|
||||||
// Set the flag so the driver can later do the actual centering.
|
|
||||||
cnf.center = true
|
|
||||||
})
|
|
||||||
case system.ActionClose:
|
case system.ActionClose:
|
||||||
w.closing = true
|
w.closing = true
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user