Skip to content

Commit

Permalink
Add pinned windows which stick to the position when moving desktops
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jun 2, 2024
1 parent d32b33d commit fa20d40
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 10 deletions.
3 changes: 1 addition & 2 deletions internal/ui/desk.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ func (l *desktop) SetDesktop(id int) {

fyne.NewAnimation(canvas.DurationStandard, func(f float32) {
for i, item := range l.wm.Windows() {
// TODO move this to floating once we support them
if item.Properties().SkipTaskbar() {
if item.Pinned() {
continue
}

Expand Down
24 changes: 24 additions & 0 deletions internal/x11/win/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type client struct {
full bool
iconic bool
maximized bool
pinned bool
props *clientProperties

restoreX, restoreY int16
Expand Down Expand Up @@ -129,6 +130,10 @@ func (c *client) SetDesktop(id int) {
diff := id - c.desk
c.desk = id

if c.pinned {
return
}

_, height := d.RootSizePixels()
offPix := float32(diff * -int(height))
display := d.Screens().ScreenForWindow(c)
Expand Down Expand Up @@ -312,6 +317,16 @@ func (c *client) Parent() fynedesk.Window {
return nil
}

func (c *client) Pin() {
c.pinned = true
d := fynedesk.Instance()
c.SetDesktop(d.Desktop())
}

func (c *client) Pinned() bool {
return c.pinned
}

func (c *client) Position() fyne.Position {
screen := fynedesk.Instance().Screens().ScreenForWindow(c)

Expand Down Expand Up @@ -409,6 +424,15 @@ func (c *client) Unmaximize() {
c.maximizeMessage(x11.WindowStateActionRemove)
}

func (c *client) Unpin() {
c.pinned = false
d := fynedesk.Instance()
id := d.Desktop()
c.desk = id

c.SetDesktop(id)
}

func (c *client) fullscreenMessage(action x11.WindowStateAction) {
err := ewmh.WmStateReq(c.wm.X(), c.win, int(action), "_NET_WM_STATE_FULLSCREEN")
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion modules/desktops/pager.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,13 @@ func (p *pager) refreshFrom(oldID int) {
continue
}

yPad := theme.Padding() * float32(win.Desktop()-oldID)
deskID := win.Desktop()
yPad := theme.Padding() * float32(deskID-oldID)
screen := fynedesk.Instance().Screens().ScreenForWindow(win)
if win.Pinned() {
yPad = theme.Padding() * float32(desk.Desktop()-oldID)
yPad -= float32(oldID-desk.Desktop()) * pivot.Size().Height
}

var obj fyne.CanvasObject
obj = canvas.NewRectangle(theme.DisabledColor())
Expand Down
1 change: 1 addition & 0 deletions modules/quaketerm/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (t *term) toggle() {
if !t.shown {
t.win = t.getHandle()

t.win.Pin()
t.show()
} else {
t.hide()
Expand Down
18 changes: 17 additions & 1 deletion test/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type Window struct {
props dummyProperties

iconic, focused, fullscreen, maximized, raised bool
iconic, focused, fullscreen, maximized, raised, pinned bool

parent fynedesk.Window
x, y, desk int
Expand Down Expand Up @@ -89,6 +89,16 @@ func (w *Window) Parent() fynedesk.Window {
return w.parent
}

// Pin requests that the window be visible on all desktops
func (w *Window) Pin() {
w.pinned = true
}

// Pinned returns true if the window should be visible on all desktops
func (w *Window) Pinned() bool {
return w.pinned
}

// Position returns 0, 0 for test windows
func (w *Window) Position() fyne.Position {
return fyne.NewPos(0, 0)
Expand Down Expand Up @@ -165,3 +175,9 @@ func (w *Window) Uniconify() {
func (w *Window) Unmaximize() {
w.maximized = false
}

// Unpin resets the state of being visible on all windows.
// The window will return to being visible on its specified desktop.
func (w *Window) Unpin() {
w.pinned = false
}
3 changes: 3 additions & 0 deletions window.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type Window interface {

Desktop() int
SetDesktop(int)
Pin()
Pinned() bool
Unpin()
}

// WindowProperties encapsulates the metadata that a window can provide.
Expand Down
34 changes: 28 additions & 6 deletions wm/border.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ func (c *Border) showMenu(from fyne.CanvasObject) {
if c.win.Maximized() {
max.Checked = true
}

pos := c.win.Position()
menuPos := pos.Add(from.Position())
menu := fyne.NewMenu("",
title,
fyne.NewMenuItemSeparator(),
Expand All @@ -150,26 +153,45 @@ func (c *Border) showMenu(from fyne.CanvasObject) {
}),
max,
fyne.NewMenuItemSeparator(),
c.makeDesktopMenu(),
c.makeDesktopMenu(menuPos),
fyne.NewMenuItemSeparator(),
fyne.NewMenuItem("Close", func() {
c.win.Close()
}))

pos := c.win.Position()
fynedesk.Instance().ShowMenuAt(menu, pos.Add(from.Position()))
fynedesk.Instance().ShowMenuAt(menu, menuPos)
}

func (c *Border) makeDesktopMenu() *fyne.MenuItem {
func (c *Border) makeDesktopMenu(pos fyne.Position) *fyne.MenuItem {
desks := make([]*fyne.MenuItem, 4)
for i := 0; i < 4; i++ {
deskID := i
desks[i] = fyne.NewMenuItem(fmt.Sprintf("Desktop %d", i+1), func() {
if c.win.Pinned() {
c.win.Unpin()
}

c.win.SetDesktop(deskID)
})
}
ret := fyne.NewMenuItem("Move to Desktop", nil)
ret.ChildMenu = fyne.NewMenu("", desks...)
pin := fyne.NewMenuItem("All Desktops", func() {
if c.win.Pinned() {
return
}

c.win.Pin()
})
if c.win.Pinned() {
pin.Checked = true
}
desks = append(desks, pin)

ret := fyne.NewMenuItem("Move to Desktop", func() {
fynedesk.Instance().ShowMenuAt(fyne.NewMenu("", desks...),
pos.Add(fyne.NewSize(40, 120)))

})
ret.ChildMenu = fyne.NewMenu("") // No-op to add the arrow...
return ret
}

Expand Down

0 comments on commit fa20d40

Please sign in to comment.