From 87041b20383b5c3fc3367e3c7722be39ba7e4701 Mon Sep 17 00:00:00 2001 From: slava Date: Thu, 23 Mar 2006 21:24:26 +0000 Subject: [PATCH] Deallocate the GLX context and visual in the proper way --- TODO.FACTOR.txt | 2 +- library/x11/glx-utils.factor | 3 +++ library/x11/ui.factor | 4 +++- library/x11/windows.factor | 9 +++++---- library/x11/xlib.factor | 4 ++++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 14dbaf1483..2082b0da71 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -23,7 +23,7 @@ - collapsing an outliner is broken - x11: - - dealloc glx context, call xfree, etc + - title bars are funny - input methods - cocoa: - global menu bar with useful commands diff --git a/library/x11/glx-utils.factor b/library/x11/glx-utils.factor index daa9caff13..7bc7b9f3e4 100644 --- a/library/x11/glx-utils.factor +++ b/library/x11/glx-utils.factor @@ -16,3 +16,6 @@ USING: alien arrays errors kernel namespaces sequences ; : create-context ( XVisualInfo* -- GLXContext ) >r dpy get r> f 1 glXCreateContext [ "Failed to create GLX context" throw ] unless* ; + +: destroy-context ( GLXContext -- ) + dpy get swap glXDestroyContext ; diff --git a/library/x11/ui.factor b/library/x11/ui.factor index ef3da8ad5f..d3179c4a62 100644 --- a/library/x11/ui.factor +++ b/library/x11/ui.factor @@ -92,7 +92,9 @@ M: world key-up-event ( event world -- ) 2drop ; M: world client-event ( event world -- ) swap close-box? [ - dup world-handle first >r close-world r> destroy-window* + dup world-handle + >r close-world + r> first2 destroy-window* ] [ drop ] if ; diff --git a/library/x11/windows.factor b/library/x11/windows.factor index 8cc861be12..d0e7678e50 100644 --- a/library/x11/windows.factor +++ b/library/x11/windows.factor @@ -34,14 +34,15 @@ USING: alien hashtables kernel math namespaces sequences ; window-attributes XCreateWindow ; : glx-window ( dim -- window context ) - first2 choose-visual [ create-window ] keep create-context ; + first2 choose-visual + [ [ create-window ] keep create-context ] keep XFree ; : destroy-window ( win -- ) dpy get swap XDestroyWindow drop ; -: destroy-window* ( win -- ) - dup windows get remove-hash destroy-window ; - +: destroy-window* ( win context -- ) + destroy-context dup windows get remove-hash destroy-window ; + : set-closable ( win -- ) dpy get swap "WM_DELETE_WINDOW" x-atom 1 XSetWMProtocols drop ; diff --git a/library/x11/xlib.factor b/library/x11/xlib.factor index dded6c2eff..cf59e57b57 100644 --- a/library/x11/xlib.factor +++ b/library/x11/xlib.factor @@ -1317,5 +1317,9 @@ FUNCTION: Status XSetStandardProperties ( : PropModePrepend 1 ; inline : PropModeAppend 2 ; inline +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! The rest of the stuff is not from the book. +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +FUNCTION: void XFree ( void* data ) ; FUNCTION: int XStoreName ( Display* display, Window w, char* window_name ) ;