-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from fyne-io/feature/positioning2
Move window positioning logic out of X11
- Loading branch information
Showing
14 changed files
with
151 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package wm | ||
|
||
import "fyne.io/fynedesk" | ||
|
||
// ScaleToPixels calculates the pixels required to show a specified Fyne dimension on the given screen | ||
func ScaleToPixels(i int, screen *fynedesk.Screen) int { | ||
return int(float32(i) * screen.CanvasScale()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package wm | ||
|
||
import ( | ||
"fyne.io/fynedesk" | ||
"fyne.io/fynedesk/theme" | ||
) | ||
|
||
// PositionForNewWindow returns the suggested position for a new window of the given geometry. | ||
// The screen list hints at available space, but normally list.Active() is the best. | ||
func PositionForNewWindow(x, y int, w, h uint, decorated bool, | ||
screens fynedesk.ScreenList) (int, int, uint, uint) { | ||
|
||
target := screens.Active() | ||
offX, offY := 0, 0 | ||
if decorated { | ||
offX = ScaleToPixels(theme.BorderWidth, target) | ||
offY = ScaleToPixels(theme.TitleHeight, target) | ||
} | ||
|
||
return target.X + offX, target.Y + offY, w, h | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package wm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"fyne.io/fynedesk" | ||
"fyne.io/fynedesk/test" | ||
"fyne.io/fynedesk/theme" | ||
) | ||
|
||
func TestPositionForNewWindow_TopLeft(t *testing.T) { | ||
screen := &fynedesk.Screen{X: 50, Y: 0, Width: 500, Height: 500, Scale: 1} | ||
x, y, _, _ := PositionForNewWindow(0, 0, 100, 100, true, test.NewScreensProvider(screen)) | ||
|
||
assert.Equal(t, 50+theme.BorderWidth, x) | ||
assert.Equal(t, theme.TitleHeight, y) | ||
} | ||
|
||
func TestPositionForNewWindow_TopLeftBorderless(t *testing.T) { | ||
screen := &fynedesk.Screen{X: 50, Y: 0, Width: 500, Height: 500, Scale: 1} | ||
x, y, _, _ := PositionForNewWindow(0, 0, 100, 100, false, test.NewScreensProvider(screen)) | ||
|
||
assert.Equal(t, 50, x) | ||
assert.Equal(t, 0, y) | ||
} |