summaryrefslogtreecommitdiff
path: root/sysdata_windows.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-06-11 10:01:55 -0400
committerPietro Gagliardi <[email protected]>2014-06-11 10:01:55 -0400
commitd14ee7f3ddc76755495b42730124f8c1be66dd15 (patch)
tree1d19514b7343c67ffad18c67a24b7ca6429da0be /sysdata_windows.go
parent0e620c4d34193089e5529623ad1655744a5e0b89 (diff)
Fixed the implementation of sysData.center() on Windows to be thread-safe; also added center() to the _xSysData interface.
Diffstat (limited to 'sysdata_windows.go')
-rw-r--r--sysdata_windows.go36
1 files changed, 33 insertions, 3 deletions
diff --git a/sysdata_windows.go b/sysdata_windows.go
index 76c068c..99dbad8 100644
--- a/sysdata_windows.go
+++ b/sysdata_windows.go
@@ -515,6 +515,7 @@ func (s *sysData) setWindowSize(width int, height int) error {
return fmt.Errorf("error getting upper-left of window for resize: %v", r.err)
}
// 0 because (0,0) is top-left so no winheight
+ // TODO this needs to be run on uitask!
err := s.setRect(int(rect.left), int(rect.top), width, height, 0)
if err != nil {
return fmt.Errorf("error actually resizing window: %v", err)
@@ -688,12 +689,41 @@ func (s *sysData) repaintAll() {
func (s *sysData) center() {
var ws _RECT
- _getWindowRect.Call(uintptr(s.hwnd), uintptr(unsafe.Pointer(&ws)))
- dw, _, _ := _getSystemMetrics.Call(_SM_CXFULLSCREEN)
- dh, _, _ := _getSystemMetrics.Call(_SM_CYFULLSCREEN)
+
+ ret := make(chan uiret)
+ defer close(ret)
+ uitask <- &uimsg{
+ call: _getWindowRect,
+ p: []uintptr{
+ uintptr(s.hwnd),
+ uintptr(unsafe.Pointer(&ws)),
+ },
+ ret: ret,
+ }
+ r := <-ret
+ if r.ret == 0 {
+ panic(fmt.Errorf("error getting window rect for sysData.center(): %v", r.err))
+ }
+ // TODO should this be using the monitor functions instead? http://blogs.msdn.com/b/oldnewthing/archive/2005/05/05/414910.aspx
+ // error returns from GetSystemMetrics() is meaningless because the return value, 0, is still valid
+ uitask <- &uimsg{
+ call: _getSystemMetrics,
+ p: []uintptr{uintptr(_SM_CXFULLSCREEN)},
+ ret: ret,
+ }
+ r = <-ret
+ dw := r.ret
+ uitask <- &uimsg{
+ call: _getSystemMetrics,
+ p: []uintptr{uintptr(_SM_CYFULLSCREEN)},
+ ret: ret,
+ }
+ r = <-ret
+ dh := r.ret
ww := ws.right - ws.left
wh := ws.bottom - ws.top
wx := (int32(dw) / 2) - (ww / 2)
wy := (int32(dh) / 2) - (wh / 2)
+ // TODO this needs to be run on uitask!
s.setRect(int(wx), int(wy), int(ww), int(wh), 0)
}