Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
I'm making a gui toolkit using Xlib and Cairo. Each widget has event properties containing Lua script event functions Usually everything works great. However approximately once out of every half ...
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    34

    [SOLVED] Xlib ConfigureNotify strangeness

    I'm making a gui toolkit using Xlib and Cairo.
    Each widget has event properties containing Lua script event functions

    Usually everything works great.

    However approximately once out of every half dozen times the application runs, it goes crazy with the window sizing from its start size to its later set size back and forth. (no Lua script is being run)

    normally my Event loop debug log contains
    Code:
    1 ConfigureNotify for window 73400321
    2 Expose count 0
    3 ConfigureNotify for window 73400321
    during an abnormal run it will look like this
    Code:
    1 ConfigureNotify for window 73400321
    2 ConfigureNotify for window 73400321
    3 ConfigureNotify for window 73400321
    4 ConfigureNotify for window 73400321
    5 Expose count 0
    6 ConfigureNotify for window 73400321
    7 ConfigureNotify for window 73400321
    8 Expose count 0
    9 ConfigureNotify for window 73400321
    10 Expose count 0
    and continue like this until stopped

    ConfigureNotify in my event loop calls this code
    Code:
    void CCGform::resize(int xs,int ys) {
    	if (xs!=width || ys!=height) {
    		XResizeWindow(disp, win, xs, ys);
    	
    		// any way to resize both without destroying?
    		// just resizing cairo surface doesnt resize the pixmap...
    		XFreePixmap(disp, backPix);
    		backPix=XCreatePixmap(disp, win, xs, ys, depth);
    		cairo_surface_destroy(back);
    		back=cairo_xlib_surface_create(disp, backPix, DefaultVisual(disp, 0), xs, ys);
    	
    		cairo_xlib_surface_set_size(front,xs,ys);
    		width=xs;
    		height=ys;
    	}
    }
    has anyone else seen this sort of behavior? anyone got any clues?

    I have no idea why it happens intermittently but I can make it more likely to happen if the application opens multiple forms

    heres my event mask
    ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask |
    SubstructureNotifyMask | KeyPressMask | LeaveWindowMask | ExposureMask

    Let me know if you think any other info is pertinent.

    TIA
    Chris

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    First off, I have no idea what Cairo is, so please bear with me. But a few questions suggest themselves.
    1. In the event structure, there's an event member and a window member. They may or not be the same. Which one are you dumping to your log?
    2. During the misbehavior, are the event and window members identical, or different?
    3. During the multiple events, do any of the members of the event structure change?
    4. Pay particular attention to the above member of the event structure. Does this change? If so, it probably means the reordering of the window with respect to its siblings.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Mar 2008
    Posts
    34
    Quote Originally Posted by wje_lf View Post
    First off, I have no idea what Cairo is, so please bear with me. But a few questions suggest themselves.
    cairo (cairographics.org) is a vector graphics library

    Quote Originally Posted by wje_lf View Post
    In the event structure, there's an event member and a window member. They may or not be the same. Which one are you dumping to your log?
    I've only dumped event.xconfigure.window the 1st number is always an event loop counter

    Quote Originally Posted by wje_lf View Post
    During the misbehavior, are the event and window members identical, or different?
    not sure what you mean there??
    but each "form" (window) is tracked by a C++ class which is found but the window id in the event structure, the event loop uses member functions from this class to respond to the corresponding event type

    Quote Originally Posted by wje_lf View Post
    During the multiple events, do any of the members of the event structure change?
    multiple events?

    Quote Originally Posted by wje_lf View Post
    Pay particular attention to the above member of the event structure. Does this change? If so, it probably means the reordering of the window with respect to its siblings.
    heres more debug log for ConfigureNotify you have event loop number,window id and above value
    Code:
    275 Expose count 0
    276 ConfigureNotify for window 75497494 20995090
    277 Expose count 0
    278 ConfigureNotify for window 75497476 20995076
    279 Expose count 0
    280 ConfigureNotify for window 75497488 20995086
    281 ConfigureNotify for window 75497491 20995088
    282 ConfigureNotify for window 75497494 20995090
    283 ConfigureNotify for window 75497476 20995076
    284 ConfigureNotify for window 75497476 20995076
    285 Expose count 0
    286 ConfigureNotify for window 75497479 20995078
    287 Expose count 0
    288 ConfigureNotify for window 75497479 20995078
    I've noticed that if I don't resize in code I can resize the windows with the mouse as much as I like.

    If I do resize once per form in code then *sometimes* when the app runs I can the odd behavior

    Is there a recommended way to resize a window using xlib from your application code?

    Thanks
    Chris

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    During the misbehavior, are the event and window members identical, or different?
    You say you're dumping event.xconfigure.window. It would be nice to dump also event.xconfigure.event. That's a window ID also, and it might be the same as event.xconfigure.window and it might be different. event.xconfigure.window is the ID of the window whose configuration changed; event.xconfigure.event is the ID of the window that selected the event. They're not necessarily the same, since you've enabled SubstructureNotifyMask.
    During the multiple events, do any of the members of the event structure change?
    multiple events?
    Yes, multiple events. Each line you've posted from your debug log represents an event. Since there are many of them, I'm referring to these many events as "multiple events". For each event, it would be nice to dump all members of the event structure, to see whether any of them change from one of these multiple events to another.
    heres more debug log for ConfigureNotify you have event loop number,window id and above value
    Bingo! See how the above value changes from one event to the next? That value shows which other sibling window this window is above. I'm guessing those windows are being created and made visible one at a time, and each one is placed just below the window corresponding to the event.

    Or.

    Or, more likely, you have a whole slew of sibling windows for the window of interest, and they're being destroyed, one by one, so that the window of interest is first immediately above one window, then as that window is destroyed, then the window is then immediately above another window, and so on.

    Or.

    Or, possibly, something is causing the window's siblings to change in their relative order, without creating or destroying anything.

    My suggestion is this: if you're not interested in the ordering of this window with respect to its siblings, then just live with the multiple events, responding to any data of interest in each such event such as window dimensions.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5
    Just Joined!
    Join Date
    Mar 2008
    Posts
    34
    I've since removed SubstructureNotifyMask

    event.window & event.xconfigure.window are always the same
    Code:
    serial 16221  send event?0
    969 ConfigureNotify for window 83886087, serial 16221
    xconfigure.window 83886087
    xs 256, ys 256, oldwidth 400, oldheight 100
    serial 16221  send event?0
    970 ConfigureNotify for window 83886087, serial 16221
    xconfigure.window 83886087
    xs 400, ys 100, oldwidth 256, oldheight 256
    serial 16261  send event?0
    971 ConfigureNotify for window 83886090, serial 16261
    xconfigure.window 83886090
    xs 256, ys 256, oldwidth 400, oldheight 100
    serial 16261  send event?0
    972 ConfigureNotify for window 83886090, serial 16261
    xconfigure.window 83886090
    xs 400, ys 100, oldwidth 256, oldheight 256
    serial 16261  send event?0
    973 ConfigureNotify for window 83886084, serial 16261
    xconfigure.window 83886084
    xs 256, ys 256, oldwidth 400, oldheight 100
    serial 16261  send event?0
    974 ConfigureNotify for window 83886084, serial 16261
    xconfigure.window 83886084
    xs 400, ys 100, oldwidth 256, oldheight 256
    its just flipping between its previous and current size and I cant see any way to distinguish the events....

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    You actually have two windows represented in that dump. Each of them appears to be alternating between one shape/size and another.

    I haven't a clue as to why that is happening. I'd say you have some serious debugging to do. :)

    Are you using some library which is changing those window sizes for you? If so, I'd find a place on the web which specializes in that library.

    Sorry I couldn't be of more help.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  7. #7
    Just Joined!
    Join Date
    Mar 2008
    Posts
    34
    Quote Originally Posted by wje_lf View Post
    You actually have two windows represented in that dump. Each of them appears to be alternating between one shape/size and another.
    The app has several windows open


    Quote Originally Posted by wje_lf View Post
    Are you using some library which is changing those window sizes for you? If so, I'd find a place on the web which specializes in that library.
    I'm using XResizeWindow (see the resize method above) do you know somewhere on the web that specializes in Xlib?

    Thanks
    Chris

  8. #8
    Just Joined!
    Join Date
    Mar 2008
    Posts
    34
    Made a fugly work-a-round that will let me get on with actually writing my app!

    Code:
    		XSelectInput(disp, win, ButtonPressMask
    			| ButtonReleaseMask
    			| PointerMotionMask
    			| KeyPressMask 
    			| LeaveWindowMask
    			| ExposureMask);
    
    		XResizeWindow(disp, win, xs, ys);
    		XSync(disp,false);
    
    		XSelectInput(disp, win, ButtonPressMask
    			| ButtonReleaseMask
    			| PointerMotionMask
    			| StructureNotifyMask
    			| KeyPressMask 
    			| LeaveWindowMask
    			| ExposureMask);
    basically I'd ignoring StructureNotify just for the actual resize, while it works I wish I knew why XResizeWindow is sending new events with the previous size..??

  9. #9
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I've never actually used ConfigureNotify events, and I don't have the time to play with them at the moment. But are you saying that for each and every resize of this window, you're getting exactly two ConfigureNotify events, one with the old size and one with the new size?

    I'm guessing that this window is a child of the root window (rather than being the child of some other window). When you attempt to resize a child of the root window, it doesn't happen right away. Instead, the window manager catches the resize request and decides whether to ignore the request, honor it as is, or change it. For example, the window manager might decide that no window may be resized to have less than some minimum width or height.

    It could be that the window manager is honoring your requests unmodified, but you're still getting two events because of this. Just a guess.

    One useful thing to know is this: Why do you want ConfigureNotify events in the first place? Is this for curiosity alone? (That would not be a bad reason.) Or do you wish to check for data other than width and height of the window?

    If there's no particular reason to catch ConfigureNotify events, you may just wish to ignore them all the time. It would make your code less kludgey.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  10. #10
    Just Joined!
    Join Date
    Mar 2008
    Posts
    34
    Quote Originally Posted by wje_lf View Post
    I've never actually used ConfigureNotify events, and I don't have the time to play with them at the moment. But are you saying that for each and every resize of this window, you're getting exactly two ConfigureNotify events, one with the old size and one with the new size?
    herein lies the problem, I only get the behavior *sometimes*

    Quote Originally Posted by wje_lf View Post
    I'm guessing that this window is a child of the root window
    Yes thats what I'm doing, I'm also assuming its ok for an app to have multiple windows that are a children of the root?

    Quote Originally Posted by wje_lf View Post
    One useful thing to know is this: Why do you want ConfigureNotify events in the first place? Is this for curiosity alone? (That would not be a bad reason.) Or do you wish to check for data other than width and height of the window?
    I need to know when the window resizes as I'm using a pixmap as a "back buffer" I do all the drawing to the pixmap and then copy the pixmap to the window only after all the widgets are drawn. You cant resize a pixmap so I have to delete an remake the cairo surface and pixmap.
    I suppose I could make the pixmap the same size as the screen for each window but this seems rather wasteful and in any case I'd like the end user to be able to run some lua code if they want to as an onResize event script...

    Thanks
    C

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...