c++ - XLib application not redrawing unless resized -


so, have application in c++ uses xlib. in it, access date , time using ctime library, , in expose event, create string , put in window, centered. problem that, time updates when resized, instance, seconds not change unless continually resize window. here code:

#include <stdio.h> #include <cstdio> #include <stdlib.h> #include <string.h> #include <x11/xlib.h> #include <ctime>  int main (int argc, char *argv[]) {   display                 *display;   visual                  *visual;   int                     depth;   int                     text_x;   int                     text_y;   xsetwindowattributes    frame_attributes;   window                  frame_window;   xfontstruct             *fontinfo;   xgcvalues               gr_values;   gc                      graphical_context;   xkeyevent               event;   char                    contents[80] = "                                                                               ";   time_t                  rawtime;   struct tm               *timeinfo;   int                     contents_length = strlen(contents);    display = xopendisplay(null);   visual = defaultvisual(display, 0);   depth  = defaultdepth(display, 0);    frame_attributes.background_pixel = xwhitepixel(display, 0);   /* create application window */   frame_window = xcreatewindow(display, xrootwindow(display, 0),       0, 0, 500, 50, 5, depth,       inputoutput, visual, cwbackpixel,       &frame_attributes);   xstorename(display, frame_window, "fly taskbar");   xselectinput(display, frame_window, exposuremask | structurenotifymask);    fontinfo = xloadqueryfont(display, "10x20");   gr_values.font = fontinfo->fid;   gr_values.foreground = xblackpixel(display, 0);   graphical_context = xcreategc(display, frame_window,       gcfont+gcforeground, &gr_values);   xmapwindow(display, frame_window);    while ( 1 ) {     xnextevent(display, (xevent *)&event);     switch ( event.type ) {       case expose:         {           xclearwindow(display, frame_window);           // upkeep of interface usefulness.           window returned_root, returned_parent;           window* top_level_windows;           unsigned int nwin = 0;           xquerytree(               display,               xdefaultrootwindow(display),               &returned_root,               &returned_parent,               &top_level_windows,               &nwin);            time(&rawtime);           timeinfo = localtime(&rawtime);           strftime(contents, 80, "%a %d %b, %t %p", timeinfo);            sprintf(contents, "%s [%d]", contents, nwin);             xwindowattributes window_attributes;           int font_direction, font_ascent, font_descent;           xcharstruct text_structure;           xtextextents(fontinfo, contents, contents_length,               &font_direction, &font_ascent, &font_descent,               &text_structure);           xgetwindowattributes(display, frame_window, &window_attributes);           text_x = (window_attributes.width - text_structure.width) + 5;           text_y = (window_attributes.height -               (text_structure.ascent+text_structure.descent))/2;           xdrawstring(display, frame_window, graphical_context,               text_x, text_y, contents, contents_length);           break;         }       default:         break;     }   }   return 0; } 

in case of wondering purpose for, writing window manager (i've gotten far, can open apps, move, , resize them) , tool need debugging purposes. repo here

you need event loop, e.g. calling poll(2) , handle delays. should call xflush or xsync (because xlib buffering requests).

you might consider sending expose event....

and should study source code of xclock


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -