Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/exp/shiny/screen: add Window.SetTitle #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions shiny/driver/gldriver/cocoa.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void stopDriver();
void makeCurrentContext(uintptr_t ctx);
void flushContext(uintptr_t ctx);
uintptr_t doNewWindow(int width, int height, char* title);
void doSetTitle(uintptr_t id, char* title);
void doShowWindow(uintptr_t id);
void doCloseWindow(uintptr_t id);
uint64_t threadID();
Expand Down Expand Up @@ -81,6 +82,13 @@ func showWindow(w *windowImpl) {
C.doShowWindow(C.uintptr_t(w.id))
}

func setTitle(id uintptr, title string) {
ctitle := C.CString(title)
defer C.free(unsafe.Pointer(ctitle))

C.doSetTitle(C.uintptr_t(id), ctitle)
}

//export preparedOpenGL
func preparedOpenGL(id, ctx, vba uintptr) {
theScreen.mu.Lock()
Expand Down
8 changes: 8 additions & 0 deletions shiny/driver/gldriver/cocoa.m
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ uintptr_t doNewWindow(int width, int height, char* title) {
return (uintptr_t)view;
}

void doSetTitle(uintptr_t viewID, char* title) {
ScreenGLView* view = (ScreenGLView*)viewID;
NSString* name = [[NSString alloc] initWithUTF8String:title];
dispatch_async(dispatch_get_main_queue(), ^{
[view.window setTitle:name];
});
}

void doShowWindow(uintptr_t viewID) {
ScreenGLView* view = (ScreenGLView*)viewID;
dispatch_async(dispatch_get_main_queue(), ^{
Expand Down
9 changes: 5 additions & 4 deletions shiny/driver/gldriver/other.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ var errUnsupported = fmt.Errorf("gldriver: unsupported GOOS/GOARCH %s/%s or cgo

func newWindow(opts *screen.NewWindowOptions) (uintptr, error) { return 0, errUnsupported }

func initWindow(id *windowImpl) {}
func showWindow(id *windowImpl) {}
func closeWindow(id uintptr) {}
func drawLoop(w *windowImpl) {}
func initWindow(id *windowImpl) {}
func showWindow(id *windowImpl) {}
func closeWindow(id uintptr) {}
func drawLoop(w *windowImpl) {}
func setTitle(id uintptr, title string) {}

func surfaceCreate() error { return errUnsupported }
func main(f func(screen.Screen)) error { return errUnsupported }
4 changes: 4 additions & 0 deletions shiny/driver/gldriver/win32.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func showWindow(w *windowImpl) {

func closeWindow(id uintptr) {} // TODO

func setTitle(id uintptr, title string) {
_ = win32.SetWindowTitle(syscall.Handle(id), title)
}

func drawLoop(w *windowImpl) {
runtime.LockOSThread()

Expand Down
4 changes: 4 additions & 0 deletions shiny/driver/gldriver/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,7 @@ func (w *windowImpl) Publish() screen.PublishResult {

return res
}

func (w *windowImpl) SetTitle(title string) {
setTitle(w.id, title)
}
6 changes: 6 additions & 0 deletions shiny/driver/gldriver/x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ doCloseWindow(uintptr_t id) {
XDestroyWindow(x_dpy, win);
}

void
doSetTitle(uintptr_t id, char* title, int title_len) {
Window win = (Window)(id);
XChangeProperty(x_dpy, win, net_wm_name, utf8_string, 8, PropModeReplace, title, title_len);
}

uintptr_t
doNewWindow(int width, int height, char* title, int title_len) {
XSetWindowAttributes attr;
Expand Down
16 changes: 16 additions & 0 deletions shiny/driver/gldriver/x11.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void processEvents();
void makeCurrent(uintptr_t ctx);
void swapBuffers(uintptr_t ctx);
void doCloseWindow(uintptr_t id);
void doSetTitle(uintptr_t id, char* title, int title_len);
uintptr_t doNewWindow(int width, int height, char* title, int title_len);
uintptr_t doShowWindow(uintptr_t id);
uintptr_t surfaceCreate();
Expand Down Expand Up @@ -98,6 +99,21 @@ func closeWindow(id uintptr) {
}
}

func setTitle(id uintptr, title string) {
ctitle := C.CString(title)
defer C.free(unsafe.Pointer(ctitle))

retc := make(chan uintptr)
uic <- uiClosure{
f: func() uintptr {
C.doSetTitle(C.uintptr_t(id), ctitle, C.int(len(title)))
return 0
},
retc: retc,
}
<-retc
}

func drawLoop(w *windowImpl) {
glcontextc <- w.ctx.(uintptr)
go func() {
Expand Down
7 changes: 4 additions & 3 deletions shiny/driver/internal/win32/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,18 @@ func _HIWORD(l uintptr) uint16 {
//sys _DispatchMessage(msg *_MSG) (ret int32) = user32.DispatchMessageW
//sys _GetClientRect(hwnd syscall.Handle, rect *_RECT) (err error) = user32.GetClientRect
//sys _GetWindowRect(hwnd syscall.Handle, rect *_RECT) (err error) = user32.GetWindowRect
//sys _GetKeyboardLayout(threadID uint32) (locale syscall.Handle) = user32.GetKeyboardLayout
//sys _GetKeyboardState(lpKeyState *byte) (err error) = user32.GetKeyboardState
//sys _GetKeyboardLayout(threadID uint32) (locale syscall.Handle) = user32.GetKeyboardLayout
//sys _GetKeyboardState(lpKeyState *byte) (err error) = user32.GetKeyboardState
//sys _GetKeyState(virtkey int32) (keystatus int16) = user32.GetKeyState
//sys _GetMessage(msg *_MSG, hwnd syscall.Handle, msgfiltermin uint32, msgfiltermax uint32) (ret int32, err error) [failretval==-1] = user32.GetMessageW
//sys _LoadCursor(hInstance syscall.Handle, cursorName uintptr) (cursor syscall.Handle, err error) = user32.LoadCursorW
//sys _LoadIcon(hInstance syscall.Handle, iconName uintptr) (icon syscall.Handle, err error) = user32.LoadIconW
//sys _MoveWindow(hwnd syscall.Handle, x int32, y int32, w int32, h int32, repaint bool) (err error) = user32.MoveWindow
//sys _PostMessage(hwnd syscall.Handle, uMsg uint32, wParam uintptr, lParam uintptr) (lResult bool) = user32.PostMessageW
//sys _PostQuitMessage(exitCode int32) = user32.PostQuitMessage
//sys _PostQuitMessage(exitCode int32) = user32.PostQuitMessage
//sys _RegisterClass(wc *_WNDCLASS) (atom uint16, err error) = user32.RegisterClassW
//sys _ShowWindow(hwnd syscall.Handle, cmdshow int32) (wasvisible bool) = user32.ShowWindow
//sys _SetWindowTextW(hwnd syscall.Handle, lpString *uint16) (err error) = user32.SetWindowTextW
//sys _ScreenToClient(hwnd syscall.Handle, lpPoint *_POINT) (ok bool) = user32.ScreenToClient
//sys _ToUnicodeEx(wVirtKey uint32, wScanCode uint32, lpKeyState *byte, pwszBuff *uint16, cchBuff int32, wFlags uint32, dwhkl syscall.Handle) (ret int32) = user32.ToUnicodeEx
//sys _TranslateMessage(msg *_MSG) (done bool) = user32.TranslateMessage
Expand Down
9 changes: 9 additions & 0 deletions shiny/driver/internal/win32/win32.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ func sendClose(hwnd syscall.Handle, uMsg uint32, wParam, lParam uintptr) (lResul
return _DefWindowProc(hwnd, uMsg, wParam, lParam)
}

func SetWindowTitle(hwnd syscall.Handle, title string) error {
ctitle, err := syscall.UTF16PtrFromString(title)
if err != nil {
return err
}

return _SetWindowTextW(hwnd, ctitle)
}

func sendMouseEvent(hwnd syscall.Handle, uMsg uint32, wParam, lParam uintptr) (lResult uintptr) {
e := mouse.Event{
X: float32(_GET_X_LPARAM(lParam)),
Expand Down
Loading