Implemented Window.Center() on GTK+.

This commit is contained in:
Pietro Gagliardi 2014-06-11 14:38:16 -04:00
parent 8632d0c2f3
commit 1414950538
1 changed files with 30 additions and 0 deletions

View File

@ -157,6 +157,11 @@ func (s *sysData) make(window *sysData) error {
return nil return nil
} }
// see sysData.center()
func (s *sysData) resetposition() {
C.gtk_window_set_position(togtkwindow(s.widget), C.GTK_WIN_POS_NONE)
}
// used for Windows; nothing special needed elsewhere // used for Windows; nothing special needed elsewhere
func (s *sysData) firstShow() error { func (s *sysData) firstShow() error {
s.show() s.show()
@ -168,6 +173,7 @@ func (s *sysData) show() {
defer close(ret) defer close(ret)
uitask <- func() { uitask <- func() {
gtk_widget_show(s.widget) gtk_widget_show(s.widget)
s.resetposition()
ret <- struct{}{} ret <- struct{}{}
} }
<-ret <-ret
@ -178,6 +184,7 @@ func (s *sysData) hide() {
defer close(ret) defer close(ret)
uitask <- func() { uitask <- func() {
gtk_widget_hide(s.widget) gtk_widget_hide(s.widget)
s.resetposition()
ret <- struct{}{} ret <- struct{}{}
} }
<-ret <-ret
@ -379,3 +386,26 @@ func (s *sysData) repaintAll() {
} }
<-ret <-ret
} }
func (s *sysData) center() {
ret := make(chan struct{})
defer close(ret)
uitask <- func() {
if C.gtk_widget_get_visible(s.widget) == C.FALSE {
// hint to the WM to make it centered when it is shown again
// thanks to Jasper in irc.gimp.net/#gtk+
C.gtk_window_set_position(togtkwindow(s.widget), C.GTK_WIN_POS_CENTER)
} else {
var width, height C.gint
s.resetposition()
//we should be able to use gravity to simplify this, but it doesn't take effect immediately, and adding show calls does nothing (thanks Jasper in irc.gimp.net/#gtk+)
C.gtk_window_get_size(togtkwindow(s.widget), &width, &height)
C.gtk_window_move(togtkwindow(s.widget),
(C.gdk_screen_width() / 2) - (width / 2),
(C.gdk_screen_height() / 2) - (width / 2))
}
ret <- struct{}{}
}
<-ret
}