#ifndef BOB_WM_H #define BOB_WM_H #include "bob_event.h" /* App-owned window records contain x,y,w,h,visible,dirty,allocated. */ #define BOB_WM_MAX_WINDOWS 8 #define BOB_WM_WINDOW_WORDS 7 #define BOB_WM_STATE_WORDS 10 /* State contains max,count,focus,drag,offset-x,offset-y,screen-w,screen-h, full-dirty,draw-cursor. Z-order is an app-owned bottom-to-top ID array. */ static int bob_wm_window_valid(const int *state,const int *windows,int id) { return state&&windows&&id>=0&&idmax_x)window[0]=max_x; if(window[1]<0)window[1]=0;if(window[1]>max_y)window[1]=max_y; } int bob_wm_init(int *state,int *windows,int *order,int maximum,int screen_width,int screen_height) { if(!state||!windows||!order||maximum<1||maximum>BOB_WM_MAX_WINDOWS|| screen_width<1||screen_height<1)return -1; for(int i=0;istate[6]||height>state[7])return -1; for(int i=0;i=state[0])return -1; int *window=windows+id*BOB_WM_WINDOW_WORDS; window[0]=x;window[1]=y;window[2]=width;window[3]=height; window[4]=1;window[5]=1;window[6]=1;bob_wm_clamp(window,state); order[state[1]++]=id;state[2]=id;state[3]=-1; for(int i=0;i=0&&old=0;i--)if(windows[order[i]*BOB_WM_WINDOW_WORDS+4]){state[2]=order[i];break;} if(state[2]>=0)windows[state[2]*BOB_WM_WINDOW_WORDS+5]=1; } bob_wm_mark_all(state,windows,order);return 1; } int bob_wm_destroy(int *state,int *windows,int *order,int id) { int index=-1,was_focused; if(!bob_wm_window_valid(state,windows,id))return -1; for(int i=0;i=0;i--)if(windows[order[i]*BOB_WM_WINDOW_WORDS+4]){state[2]=order[i];break;} } if(state[2]>=0)windows[state[2]*BOB_WM_WINDOW_WORDS+5]=1; bob_wm_mark_all(state,windows,order);return 0; } int bob_wm_window_at(const int *state,const int *windows,const int *order,int x,int y) { if(!state||!windows||!order)return -1; for(int i=state[1]-1;i>=0;i--) { int id=order[i];int *window=(int *)(windows+id*BOB_WM_WINDOW_WORDS); if(bob_wm_window_valid(state,windows,id)&&window[4]&& x>=window[0]&&y>=window[1]&&x=0) { bob_wm_focus(state,windows,order,target); int *window=windows+target*BOB_WM_WINDOW_WORDS; if((event[1]&BOB_MOUSE_BUTTON_LEFT)&&y==window[1]) { state[3]=target;state[4]=x-window[0];state[5]=y-window[1]; } } } if(target<0)return -1; routed[2]=x-windows[target*BOB_WM_WINDOW_WORDS]; routed[3]=y-windows[target*BOB_WM_WINDOW_WORDS+1]; return target; } void bob_wm_invalidate(int *state,int *windows,int *order,int id) { if(!bob_wm_window_valid(state,windows,id))return; windows[id*BOB_WM_WINDOW_WORDS+5]=1; for(int i=0;i