|
Post by alexfish on Aug 12, 2020 22:57:27 GMT 1
Peter
got a problem with compiling xcb , bacon latest fossil
this compile with WHILE usec while works , indicted at
' TODO PROBLEM WHILE ((event = xcb_wait_for_event(c))) DO ' PROBLEM SELECT while ((event = xcb_wait_for_event(c))) {
BR Alex
the code
OPTION PARSE FALSE
PRAGMA LDFLAGS `pkg-config --libs xcb` PRAGMA OPTIONS `pkg-config --cflags xcb` PRAGMA INCLUDE <xcb/xcb.h> PRAGMA INCLUDE <stdint.h>
USEC const uint32_t values = XCB_EVENT_MASK_EXPOSURE; END USEC
DECLARE c TYPE xcb_connection_t* DECLARE s TYPE xcb_screen_t* DECLARE w TYPE xcb_window_t
DECLARE cookie TYPE xcb_intern_atom_cookie_t DECLARE reply TYPE xcb_intern_atom_reply_t*
DECLARE cookie2 TYPE xcb_intern_atom_cookie_t DECLARE reply2 TYPE xcb_intern_atom_reply_t*
c = xcb_connect(0, 0) s = xcb_setup_roots_iterator(xcb_get_setup(c)).data w = xcb_generate_id(c)
xcb_create_window(c, 0, w, (*s).root, 0, 0, 128, 128, 0,XCB_WINDOW_CLASS_INPUT_OUTPUT, (*s).root_visual, XCB_CW_EVENT_MASK,&values)
cookie = xcb_intern_atom(c, 1, 12,"WM_PROTOCOLS") reply = xcb_intern_atom_reply(c, cookie, 0)
cookie2 = xcb_intern_atom(c, 0, 16,"WM_DELETE_WINDOW") reply2 = xcb_intern_atom_reply(c, cookie2, 0)
xcb_change_property(c, XCB_PROP_MODE_REPLACE, w, (*reply).atom, 4, 32, 1,&(*reply2).atom);
xcb_map_window(c, w)
xcb_flush(c)
LOCAL event TYPE xcb_generic_event_t*
' TODO PROBLEM WHILE ((event = xcb_wait_for_event(c))) DO ' PROBLEM SELECT USEC while ((event = xcb_wait_for_event(c))) { //puts("Event occurred");
switch((*event).response_type & ~0x80) { case XCB_EXPOSE: //puts("Expose"); break; case XCB_CLIENT_MESSAGE: { //puts("Client Message"); if((*(xcb_client_message_event_t*)event).data.data32[0] == (*reply2).atom) { puts("Kill client"); return 0; } break; } } } END USEC
|
|
|
Post by alexfish on Aug 12, 2020 23:58:51 GMT 1
the problem is
at while =
bacon
while(( event)== xcb_wait_for_event(c) ){
usec straight pass c;
while ((event = xcb_wait_for_event(c))) {
also need to sort select at
switch((*event).response_type & ~0x80)
BR Alex
|
|
|
Post by vovchik on Aug 13, 2020 0:07:20 GMT 1
Dear Alex,
What about this:
OPTION PARSE FALSE
PRAGMA LDFLAGS `pkg-config --libs xcb` PRAGMA OPTIONS `pkg-config --cflags xcb` PRAGMA INCLUDE <xcb/xcb.h> PRAGMA INCLUDE <stdint.h>
DECLARE values TYPE uint32_t DECLARE c TYPE xcb_connection_t* DECLARE s TYPE xcb_screen_t* DECLARE w TYPE xcb_window_t DECLARE cookie, cookie2 TYPE xcb_intern_atom_cookie_t DECLARE reply, reply2 TYPE xcb_intern_atom_reply_t* DECLARE event TYPE xcb_generic_event_t* DECLARE rt TYPE uint8_t
values = XCB_EVENT_MASK_EXPOSURE c = xcb_connect(0, 0) s = xcb_setup_roots_iterator(xcb_get_setup(c)).data w = xcb_generate_id(c) xcb_create_window(c, 0, w, (*s).root, 0, 0, 128, 128, 0,XCB_WINDOW_CLASS_INPUT_OUTPUT, (*s).root_visual, XCB_CW_EVENT_MASK, &values) cookie = xcb_intern_atom(c, 1, 12,"WM_PROTOCOLS") reply = xcb_intern_atom_reply(c, cookie, 0) cookie2 = xcb_intern_atom(c, 0, 16,"WM_DELETE_WINDOW") reply2 = xcb_intern_atom_reply(c, cookie2, 0) xcb_change_property(c, XCB_PROP_MODE_REPLACE, w, (*reply).atom, 4, 32, 1, &(*reply2).atom); xcb_map_window(c, w) xcb_flush(c)
WHILE TRUE DO event = xcb_wait_for_event(c) rt = (*event).response_type & ~0x80 SELECT rt CASE XCB_EXPOSE PRINT "Expose" CASE XCB_CLIENT_MESSAGE IF ((*(xcb_client_message_event_t*)event).data.data32[0] == (*reply2).atom) THEN PRINT "Kill client" BREAK END IF END SELECT WEND
It seems to work....
With kind regards, vovchik
|
|
|
Post by alexfish on Aug 13, 2020 1:59:44 GMT 1
Thanks Vovchik
now back up and running on one bit for xcb & cairo
as for future , the delete event is important for cleaning up xcb, and how to examples are very -1
so for reference to use xcb successfully one should use it
the reference
cookie = xcb_intern_atom(c, 1, 12,"WM_PROTOCOLS") reply = xcb_intern_atom_reply(c, cookie, 0) cookie2 = xcb_intern_atom(c, 0, 16,"WM_DELETE_WINDOW") reply2 = xcb_intern_atom_reply(c, cookie2, 0) xcb_change_property(c, XCB_PROP_MODE_REPLACE, w, (*reply).atom, 4, 32, 1, &(*reply2).atom)
and in the events loop
CASE XCB_CLIENT_MESSAGE IF ((*(xcb_client_message_event_t*)event).data.data32[0] == (*reply2).atom) THEN ' Clean up here before exit 'then PRINT "Kill client" xcb_disconnect(c) BREAK END IF
Thanks again + BR Alex
|
|
|
Post by vovchik on Aug 13, 2020 9:39:48 GMT 1
Dear Alex,
Here is another mod. I tried getting rid of some ugly pointer constructions by using "->". Only one left (in the IF statement within the WHILE loop):
OPTION PARSE FALSE
PRAGMA LDFLAGS `pkg-config --libs xcb` PRAGMA OPTIONS `pkg-config --cflags xcb` PRAGMA INCLUDE <xcb/xcb.h> PRAGMA INCLUDE <stdint.h>
DECLARE values TYPE uint32_t DECLARE c TYPE xcb_connection_t* DECLARE s TYPE xcb_screen_t* DECLARE w TYPE xcb_window_t DECLARE cookie, cookie2 TYPE xcb_intern_atom_cookie_t DECLARE reply, reply2 TYPE xcb_intern_atom_reply_t* DECLARE event TYPE xcb_generic_event_t* DECLARE rt TYPE uint8_t
values = XCB_EVENT_MASK_EXPOSURE c = xcb_connect(0, 0) s = xcb_setup_roots_iterator(xcb_get_setup(c)).data w = xcb_generate_id(c) xcb_create_window(c, 0, w, s->root, 0, 0, 128, 128, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, s->root_visual, XCB_CW_EVENT_MASK, &values) cookie = xcb_intern_atom(c, 1, 12,"WM_PROTOCOLS") reply = xcb_intern_atom_reply(c, cookie, 0) cookie2 = xcb_intern_atom(c, 0, 16,"WM_DELETE_WINDOW") reply2 = xcb_intern_atom_reply(c, cookie2, 0) xcb_change_property(c, XCB_PROP_MODE_REPLACE, w, reply->atom, 4, 32, 1, &reply2->atom) xcb_map_window(c, w) xcb_flush(c)
WHILE TRUE DO event = xcb_wait_for_event(c) rt = event->response_type & ~0x80 SELECT rt CASE XCB_EXPOSE PRINT "Expose" CASE XCB_CLIENT_MESSAGE IF (*(xcb_client_message_event_t*)event).data.data32[0] = reply2->atom THEN PRINT "Kill client" xcb_disconnect(c) BREAK END IF END SELECT WEND
With kind regards, vovchik
|
|
|
Post by bigbass on Aug 14, 2020 6:33:05 GMT 1
Hello vovchik and Alex
just looked at that really low level xcb part *Xlib also has its ugly side
what I did is just give it all some meaning so that it could be read
vovchick you did a fine job porting it I would only use more arrow operators over pointers but then it would look like what should have been the original c source code ...
what makes it ugly is they are using event twice event in the loop is xcb_generic_event_t*
then you want the xcb_client_message_event_t* now you have to cast it or it would use the generic event
its does the same but you can read it a little better
Joe
WHILE TRUE DO event = xcb_wait_for_event(c) rt = event->response_type & ~0x80 SELECT rt CASE XCB_EXPOSE PRINT "Expose" CASE XCB_CLIENT_MESSAGE CLOSE_EVENT = (*(xcb_client_message_event_t*)event).data.data32[0] CLICKED_CLOSE = reply2->atom IF CLOSE_EVENT == CLICKED_CLOSE THEN PRINT "Kill client" BREAK END IF END SELECT WEND
|
|
|
Post by bigbass on Aug 14, 2020 18:54:04 GMT 1
Hello Alex and vovchik
I had in the past done this for Xlib ,gdk,fltk and thought to try it with xcb (first time using xcb)
its pretty useful as is but you could add more Joe
I will post later how I got the "33" for the window close simplified I made a debug callback
OPTION PARSE FALSE '---modded by bigbass to get mouse buttons keycode focus keypress enter leave close window(simple)
PRAGMA LDFLAGS `pkg-config --libs xcb` PRAGMA OPTIONS `pkg-config --cflags xcb` PRAGMA INCLUDE <xcb/xcb.h> PRAGMA INCLUDE <xcb/xproto.h> PRAGMA INCLUDE <stdint.h>
'DECLARE values TYPE uint32_t DECLARE valwin[0] TYPE uint32_t DECLARE c TYPE xcb_connection_t* DECLARE s TYPE xcb_screen_t* DECLARE w TYPE xcb_window_t DECLARE cookie, cookie2 TYPE xcb_intern_atom_cookie_t DECLARE reply, reply2 TYPE xcb_intern_atom_reply_t* DECLARE event TYPE xcb_client_message_event_t* DECLARE rt TYPE uint8_t
valwin[0] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS|XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW 'values = XCB_EVENT_MASK_BUTTON_PRESS c = xcb_connect(0, 0) s = xcb_setup_roots_iterator(xcb_get_setup(c)).data w = xcb_generate_id(c) xcb_create_window(c, 0, w, s->root, 0, 0, 128, 128, 0,XCB_WINDOW_CLASS_INPUT_OUTPUT, s->root_visual, XCB_CW_EVENT_MASK , &valwin[0]) cookie = xcb_intern_atom(c, 1, 12,"WM_PROTOCOLS") reply = xcb_intern_atom_reply(c, cookie, 0) cookie2 = xcb_intern_atom(c, 0, 16,"WM_DELETE_WINDOW") reply2 = xcb_intern_atom_reply(c, cookie2, 0) xcb_change_property(c, XCB_PROP_MODE_REPLACE, w, reply->atom, 4, 32, 1, &reply2->atom) xcb_map_window(c, w) xcb_flush(c)
WHILE TRUE DO event = xcb_wait_for_event(c) rt = event->response_type & ~0x80 SELECT rt CASE XCB_EXPOSE PRINT "Expose" CASE XCB_FOCUS_IN PRINT "focus in!" CASE XCB_BUTTON_PRESS PRINT "Mouse Button pressed = " ,((xcb_button_press_event_t*)event)->detail) CASE XCB_KEY_PRESS PRINT "Keycode = " ,((xcb_key_press_event_t*)event)->detail) CASE XCB_ENTER_NOTIFY PRINT "Enter window!" CASE XCB_LEAVE_NOTIFY PRINT "Leave window!" CASE XCB_CLIENT_MESSAGE IF rt == 33 THEN PRINT "close signal !" END IF BREAK free (event) END SELECT WEND
|
|
|
Post by vovchik on Aug 14, 2020 19:07:25 GMT 1
Dear Joe, Thanks. We now have focus, keystrokes, mouse action and that lovely and intriguing 33 for exit. Very nice work. With kind regards, vovchik
|
|
|
Post by bigbass on Aug 14, 2020 19:54:10 GMT 1
Hello vovchik
this is the longer explaination version but has a debug callback here is how I figured out the 33 as you can see the number reduced alot of code it may come in handy if you want a call back to do the work this was how I thought to do it the first time but then improved it
Joe
OPTION PARSE FALSE '---modded by bigbass to get mouse buttons keycode focus keypress enter leave close window(simple)
PRAGMA LDFLAGS `pkg-config --libs xcb` PRAGMA OPTIONS `pkg-config --cflags xcb` PRAGMA INCLUDE <xcb/xcb.h> PRAGMA INCLUDE <xcb/xproto.h> PRAGMA INCLUDE <stdint.h>
'DECLARE values TYPE uint32_t DECLARE valwin[0] TYPE uint32_t DECLARE c TYPE xcb_connection_t* DECLARE s TYPE xcb_screen_t* DECLARE w TYPE xcb_window_t DECLARE cookie, cookie2 TYPE xcb_intern_atom_cookie_t DECLARE reply, reply2 TYPE xcb_intern_atom_reply_t* DECLARE event TYPE xcb_client_message_event_t* DECLARE rt TYPE uint8_t SUB GET_CLIENT_SIGNAL(xcb_connection_t *conn, xcb_window_t window) '---the magic number is rt PRINT rt CLOSE_EVENT = (*(xcb_client_message_event_t*)event).data.data32[0] CLICKED_CLOSE = reply2->atom IF CLOSE_EVENT == CLICKED_CLOSE THEN
PRINT "closed the main window " END IF xcb_flush(conn) free(event) END SUB
valwin[0] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS|XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW 'values = XCB_EVENT_MASK_BUTTON_PRESS c = xcb_connect(0, 0) s = xcb_setup_roots_iterator(xcb_get_setup(c)).data w = xcb_generate_id(c) xcb_create_window(c, 0, w, s->root, 0, 0, 128, 128, 0,XCB_WINDOW_CLASS_INPUT_OUTPUT, s->root_visual, XCB_CW_EVENT_MASK , &valwin[0]) cookie = xcb_intern_atom(c, 1, 12,"WM_PROTOCOLS") reply = xcb_intern_atom_reply(c, cookie, 0) cookie2 = xcb_intern_atom(c, 0, 16,"WM_DELETE_WINDOW") reply2 = xcb_intern_atom_reply(c, cookie2, 0) xcb_change_property(c, XCB_PROP_MODE_REPLACE, w, reply->atom, 4, 32, 1, &reply2->atom) xcb_map_window(c, w) xcb_flush(c)
WHILE TRUE DO event = xcb_wait_for_event(c) rt = event->response_type & ~0x80 SELECT rt CASE XCB_EXPOSE PRINT "Expose" CASE XCB_FOCUS_IN PRINT "focus in!" CASE XCB_BUTTON_PRESS PRINT "Mouse Button pressed = " ,((xcb_button_press_event_t*)event)->detail) CASE XCB_KEY_PRESS PRINT "Keycode = " ,((xcb_key_press_event_t*)event)->detail) CASE XCB_ENTER_NOTIFY PRINT "Enter window!" CASE XCB_LEAVE_NOTIFY PRINT "Leave window!" CASE XCB_CLIENT_MESSAGE CALL GET_CLIENT_SIGNAL(c,w) IF rt == 33 THEN PRINT "close signal !" END IF BREAK free (event) END SELECT WEND
|
|
|
Post by vovchik on Aug 14, 2020 20:33:30 GMT 1
Dear Joe (and Alex), Thanks. I think I an starting to get it now. There is a lot of good information here xcb1 and here xcb2. I am reading.... With kind regards, vovchik
|
|
|
Post by alexfish on Aug 15, 2020 8:56:33 GMT 1
Hi Joe & Vovchik thanks for the bacon tokenism's there are some nice examples HEREsome of the bits show how to identify which window has the event BR Alex
|
|
|
Post by vovchik on Aug 15, 2020 19:16:46 GMT 1
Dear Alex and Joe, Here is a slightly modded port of one of those demos. I haven't quite got the WM_DELETE_WINDOW bit working yet, but a keystroke will exit cleanly. With kind regards, vovchik
|
|
|
Post by bigbass on Aug 17, 2020 5:30:57 GMT 1
Hello vovchik
Thanks for the port of an example with drawing
Joe
|
|
|
Post by alexfish on Aug 17, 2020 11:21:20 GMT 1
Hi Vovchik & Joe & All now got back to original pi xcb bits just before the wipe out now in process of baconizing the bits + how to keep the delete cookie(cookie) separate from other cookies Will post updates on the cairo2 thread soon BR Alex Attachments:
|
|
|
Post by alexfish on Aug 17, 2020 17:06:55 GMT 1
and another screen-shot ON TARGET Just for Fun BR Alex Attachments:
|
|