From: Michael D. Lowis Date: Wed, 23 Mar 2022 02:37:10 +0000 (-0400) Subject: implemented basic window functions X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=1563dcf20dfabc3e0497bddee10a91c70269782d;p=projs%2Ftide.git implemented basic window functions --- diff --git a/src/uitest/main.c b/src/uitest/main.c index 0e2826a..76fbabf 100644 --- a/src/uitest/main.c +++ b/src/uitest/main.c @@ -3,96 +3,8 @@ int main(int argc, char** argv) { -// /* open the X display and get basic attributes */ -// x11_init(&X); -//// font_load(Fonts[FontSel = 0]); -//// X.tagfont = X.font; -//// if (!X.font) -//// { -//// perror("unable to load base font"); -//// exit(EXIT_FAILURE); -//// } -// x11_mkwin(&X, 640, 480, 0 -// | KeyPressMask -// | ButtonPressMask -// | ButtonReleaseMask -// | ButtonMotionMask -// | PropertyChangeMask -// ); -// x11_init_gc(&X); -// x11_sel_init(&X); -// -//// tide_send("ADD"); -//// job_spawn(ConnectionNumber(X.display), xupdate, 0, 0); -// XSync(X.display, False); -// -// int maxcount = 1000 / Timeout; -// int count = 0; -// while (X.state != QUITTING) -// { -// bool ready = job_poll(Timeout); -// count += (ready ? -count : 1); -// if (count < maxcount) -// { -//// xupdate(NULL); -// } -// } -// -//typedef struct { -// long x, y; -// long state; -// long rune; -//} KeyPress; // or Release -// -//typedef struct { -// long x, y; -// long state; -// long button; -//} ButtonPress; // or Release, or Drag -// -// -// /* register event handlers */ -//// X.eventfns[KeyPress] = xkeypress; -//// X.eventfns[ButtonPress] = xmousebtn; -//// X.eventfns[ButtonRelease] = xmousebtn; -//// X.eventfns[MotionNotify] = xbtnmotion; -// -//// X.eventfns[ClientMessage] = xclientmsg; -//// X.eventfns[ConfigureNotify] = xresize; -// -//// win_init(); -//// view_init(&Regions[TAGS], NULL); -//// view_init(&Regions[EDIT], NULL); -//// view_putstr(win_view(TAGS), TagString); -//// view_resize(win_view(TAGS), 640, 1); -//// buf_logclear(win_buf(TAGS)); -//// win_prop_set("TIDE", "", "tide"); -//// dbc_init(NULL, dumpdata); -//// -//// /* if we still have args left we're going to open it in this instance */ -//// if (*argv) -//// { -//// edit_file(*argv, line_num); -//// } -//// -//// /* set host name property */ -//// char buf[8192]; -//// if (!gethostname(buf, sizeof(buf))) -//// win_prop_set("HOST", "host", buf); -//// -//// /* exit */ -//// if (termcmd) -//// { -//// termcmd = strmcat("&", termcmd, 0); -//// exec_cmd(termcmd); -//// free(termcmd); -//// } -//// -//// /* now create the window and start the event loop */ -////#ifndef TEST -//// x11_show(&X); -////#endif -//// xupdate(NULL); -//// win_loop(); + UIWidget* win = UI_MakeWindow(640, 480); + UI_ShowWindow(win); + sleep(60); return 0; } diff --git a/src/uitest/ui.h b/src/uitest/ui.h index b482855..0863e5d 100644 --- a/src/uitest/ui.h +++ b/src/uitest/ui.h @@ -134,21 +134,22 @@ typedef struct XConf { extern struct XConf X; -//typedef struct { -// Window winid; -// Pixmap pixmap; -// XIC xic; -// XIM xim; -// GC gc; -//} XWindow; +typedef struct { + long width, height; + Window winid; + Pixmap pixmap; + XIC xic; + XIM xim; + GC gc; +} XWindow; int X11_Init(XConf* x); void X11_ClearError(void); XErrorEvent* X11_GetError(void); -Window X11_MakeWindow(XConf* x, int width, int height); -Window X11_MakeDialog(XConf* x, int width, int height); -//void UI_ShowWindow(UIWindow* w); -//void UI_HideWindow(UIWindow* w); +void X11_MakeWindow(XConf* x, XWindow* win, int width, int height); +void X11_MakeDialog(XConf* x, XWindow* win, int width, int height); +void X11_ShowWindow(XConf* x, XWindow* w); +void X11_HideWindow(XConf* x, XWindow* w); //void x11_resize(XConf* x, XEvent* e); //void x11_process_events(XConf* x); @@ -210,3 +211,5 @@ typedef struct UIWidget { UIWidget* UI_MakeWindow(long width, long height); UIWidget* UI_MakeDialog(void); void UI_StartEventLoop(void (*)(UIWidget*, UIEvent*)); +void UI_ShowWindow(UIWidget* w); +void UI_HideWindow(UIWidget* w); diff --git a/src/uitest/ui_window.c b/src/uitest/ui_window.c index 23c50cc..f35020c 100644 --- a/src/uitest/ui_window.c +++ b/src/uitest/ui_window.c @@ -2,36 +2,49 @@ #include "ui.h" typedef struct UIWindow { - struct UIWindow* next; UIWidget widget; - Window winid; + XWindow xwin; + struct UIWindow* next; } UIWindow; UIWindow* WindowList = NULL; -UIWidget* UI_MakeWindow(long width, long height) +UIWindow* make_window(void) { if (!WindowList) { X11_Init(&X); } UIWindow* win = calloc(1, sizeof(UIWindow)); - win->winid = X11_MakeWindow(&X, width, height); + win->next = WindowList; + WindowList = win; + return win; +} + +UIWidget* UI_MakeWindow(long width, long height) +{ + UIWindow* win = make_window(); + X11_MakeWindow(&X, &(win->xwin), width, height); + return &(win->widget); } UIWidget* UI_MakeDialog(void) { - if (!WindowList) { X11_Init(&X); } - UIWindow* win = calloc(1, sizeof(UIWindow)); - win->winid = X11_MakeDialog(&X, 640, 480); + UIWindow* win = make_window(); + X11_MakeDialog(&X, &(win->xwin), 640, 480); + return &(win->widget); } //void UI_StartEventLoop(void (*)(UIWidget*, UIEvent*)) //{ // /* TODO: implement event loop */ //} -// -//void UI_ShowWindow(UIWindow* w) -//{ -//} -// -//void UI_HideWindow(UIWindow* w) -//{ -//} + +void UI_ShowWindow(UIWidget* w) +{ + UIWindow* win = (UIWindow*)w; + X11_ShowWindow(&X, &(win->xwin)); +} + +void UI_HideWindow(UIWidget* w) +{ + UIWindow* win = (UIWindow*)w; + X11_HideWindow(&X, &(win->xwin)); +} diff --git a/src/uitest/x11.c b/src/uitest/x11.c index f2a739b..0255f6b 100644 --- a/src/uitest/x11.c +++ b/src/uitest/x11.c @@ -48,7 +48,7 @@ XErrorEvent* X11_GetError(void) return (Has_Error ? &Error : NULL); } -Window X11_MakeWindow(XConf* x, int width, int height) +void X11_MakeWindow(XConf* x, XWindow* win, int width, int height) { /* create the main window */ XSetWindowAttributes attr; @@ -66,21 +66,71 @@ Window X11_MakeWindow(XConf* x, int width, int height) | VisibilityChangeMask | StructureNotifyMask ; - Window win = XCreateWindow( + win->width = width; + win->height = height; + win->winid = XCreateWindow( x->display, x->root, 0, 0, width, height, 0, x->depth, InputOutput, x->visual, CWBackPixel | CWBitGravity | CWBackingStore | CWEventMask, &attr); /* register interest in the delete window message */ Atom wmDeleteMessage = XInternAtom(x->display, "WM_DELETE_WINDOW", False); - XSetWMProtocols(x->display, win, &wmDeleteMessage, 1); - return win; + XSetWMProtocols(x->display, win->winid, &wmDeleteMessage, 1); + +// /* set input methods */ +// if ((x->xim = XOpenIM(x->display, 0, 0, 0))) +// x->xic = XCreateIC(x->xim, XNInputStyle, XIMPreeditNothing|XIMStatusNothing, XNClientWindow, x->self, XNFocusWindow, x->self, NULL); +// /* initialize pixmap and drawing context */ +// x->pixmap = XCreatePixmap(x->display, x->self, x->width, x->height, x->depth); +// x->xft = XftDrawCreate(x->display, x->pixmap, x->visual, x->colormap); +// /* initialize the graphics context */ +// XGCValues gcv; +// gcv.foreground = WhitePixel(x->display, x->screen); +// gcv.graphics_exposures = False; +// x->gc = XCreateGC(x->display, x->self, GCGraphicsExposures, &gcv); +// x->eventfns[ConfigureNotify] = x11_resize; +// x->eventfns[MapNotify] = x11_mapnotify; +// x->eventfns[EnterNotify] = x11_enternotify; + } -Window X11_MakeDialog(XConf* x, int width, int height) +void X11_MakeDialog(XConf* x, XWindow* win, int width, int height) { - Window win = X11_MakeWindow(x, width, height); + X11_MakeWindow(x, win, width, height); Atom WindowType = XInternAtom(x->display, "_NET_WM_WINDOW_TYPE", False); Atom DialogType = XInternAtom(x->display, "_NET_WM_WINDOW_TYPE_DIALOG", False); - XChangeProperty(x->display, win, WindowType, XA_ATOM, 32, PropModeReplace, (unsigned char*)&DialogType, 1); + XChangeProperty(x->display, win->winid, WindowType, XA_ATOM, 32, PropModeReplace, (unsigned char*)&DialogType, 1); +} + +void X11_ShowWindow(XConf* x, XWindow* w) +{ + /* simulate an initial resize and map the window */ + XConfigureEvent ce; + ce.type = ConfigureNotify; + ce.width = w->width; + ce.height = w->height; + XSendEvent(x->display, w->winid, False, StructureNotifyMask, (XEvent *)&ce); + XMapWindow(x->display, w->winid); + XSync(x->display, False); + + /* Waiting for window mapping */ + XEvent ev; + do + { + XNextEvent(x->display, &ev); + if (XFilterEvent(&ev, None)) + { + continue; + } + if (ev.type == ConfigureNotify) + { +// x11_resize(x, &ev); + } + } + while (ev.type != MapNotify); +} + +void X11_HideWindow(XConf* x, XWindow* w) +{ + /* TODO: implement window hiding */ }