diff options
author | Ton Roosendaal <ton@blender.org> | 2008-12-08 18:02:57 +0300 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2008-12-08 18:02:57 +0300 |
commit | 02e23c16dd9e403deb1694829c11d16dc47392ee (patch) | |
tree | f5ec9e3f68bad13137bdeafa326281c74387327e /source/blender/windowmanager | |
parent | 11e15bf68979670b2257814aa296886222b3ee40 (diff) |
2.5
Part one of wrapping up area/region management.
Read design doc here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/AreaManager
This commit:
- brings keymap storage to WM, based on names/types. This structure
allows rna-ifying it too, so you can browse keymaps etc.
- creating areas and regions works slightly different now, wich
regiontypes stored in areatype.
Todo:
- better callbacks and structure for defining which handlers need to
be added.
- using region types to validate regions
- proper implementation of local region data
- code method for customizing keymaps. Current idea is that you have
to indicate an entire keymap to be custom, to prevent too complicated
merging problems of default and custom maps (like order, multiple keys
for same operator, disabling options, etc).
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 4 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm.c | 11 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 30 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_keymap.c | 89 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 10 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_window.c | 10 | ||||
-rw-r--r-- | source/blender/windowmanager/wm_event_system.h | 6 |
7 files changed, 100 insertions, 60 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 7bbb97d9c42..9dbb4c46947 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -67,6 +67,10 @@ void WM_keymap_verify_item(ListBase *lb, char *idname, short type, short val, int modifier, short keymodifier); void WM_keymap_add_item (ListBase *lb, char *idname, short type, short val, int modifier, short keymodifier); +ListBase *WM_keymap_listbase (wmWindowManager *wm, const char *nameid, + int spaceid, int regionid); + + struct wmEventHandler *WM_event_add_keymap_handler(ListBase *handlers, ListBase *keymap); void WM_event_remove_keymap_handler(ListBase *handlers, ListBase *keymap); diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index 7c1532210d9..3333c485aae 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -136,6 +136,7 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm) wmWindow *win; wmOperator *op; wmReport *report; + wmKeyMap *km; while((win= wm->windows.first)) { BLI_remlink(&wm->windows, win); @@ -152,11 +153,11 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm) wm_report_free(report); } - BLI_freelistN(&wm->timekeymap); - BLI_freelistN(&wm->view2dkeymap); - BLI_freelistN(&wm->uikeymap); - BLI_freelistN(&wm->windowkeymap); - BLI_freelistN(&wm->screenkeymap); + while((km= wm->keymaps.first)) { + BLI_freelistN(&km->keymap); + BLI_remlink(&wm->keymaps, km); + MEM_freeN(km); + } BLI_freelistN(&wm->queue); diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index ac153b76c7e..c74497fa10b 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -347,20 +347,20 @@ void WM_event_remove_handlers(bContext *C, ListBase *handlers) } } -static int wm_eventmatch(wmEvent *winevent, wmKeymapItem *km) +static int wm_eventmatch(wmEvent *winevent, wmKeymapItem *kmi) { - if(winevent->type!=km->type) return 0; + if(winevent->type!=kmi->type) return 0; - if(km->val!=KM_ANY) - if(winevent->val!=km->val) return 0; + if(kmi->val!=KM_ANY) + if(winevent->val!=kmi->val) return 0; - if(winevent->shift!=km->shift) return 0; - if(winevent->ctrl!=km->ctrl) return 0; - if(winevent->alt!=km->alt) return 0; - if(winevent->oskey!=km->oskey) return 0; - if(km->keymodifier) - if(winevent->keymodifier!=km->keymodifier) return 0; + if(winevent->shift!=kmi->shift) return 0; + if(winevent->ctrl!=kmi->ctrl) return 0; + if(winevent->alt!=kmi->alt) return 0; + if(winevent->oskey!=kmi->oskey) return 0; + if(kmi->keymodifier) + if(winevent->keymodifier!=kmi->keymodifier) return 0; /* optional boundbox */ @@ -449,14 +449,14 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) action= WM_HANDLER_BREAK; if(handler->keymap) { - wmKeymapItem *km; + wmKeymapItem *kmi; - for(km= handler->keymap->first; km; km= km->next) { - if(wm_eventmatch(event, km)) { + for(kmi= handler->keymap->first; kmi; kmi= kmi->next) { + if(wm_eventmatch(event, kmi)) { /* if(event->type!=MOUSEMOVE) - printf("handle evt %d win %d op %s\n", event->type, C->window->winid, km->idname); */ + printf("handle evt %d win %d op %s\n", event->type, C->window->winid, kmi->idname); */ - event->keymap_idname= km->idname; /* weak, but allows interactive callback to not use rawkey */ + event->keymap_idname= kmi->idname; /* weak, but allows interactive callback to not use rawkey */ action= wm_handler_operator_call(C, handlers, handler, event); if(action==WM_HANDLER_BREAK) /* not wm_event_always_pass(event) here, it denotes removed handler */ diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index 610222b4372..439f5c304d1 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -47,45 +47,45 @@ /* ***************** generic call, exported **************** */ -static void keymap_set(wmKeymapItem *km, short type, short val, int modifier, short keymodifier) +static void keymap_set(wmKeymapItem *kmi, short type, short val, int modifier, short keymodifier) { - km->type= type; - km->val= val; - km->keymodifier= keymodifier; + kmi->type= type; + kmi->val= val; + kmi->keymodifier= keymodifier; if(modifier & KM_SHIFT) - km->shift= 1; + kmi->shift= 1; else if(modifier & KM_SHIFT2) - km->shift= 2; + kmi->shift= 2; if(modifier & KM_CTRL) - km->ctrl= 1; + kmi->ctrl= 1; else if(modifier & KM_CTRL2) - km->ctrl= 2; + kmi->ctrl= 2; if(modifier & KM_ALT) - km->alt= 1; + kmi->alt= 1; else if(modifier & KM_ALT2) - km->alt= 2; + kmi->alt= 2; if(modifier & KM_OSKEY) - km->oskey= 1; + kmi->oskey= 1; else if(modifier & KM_OSKEY2) - km->oskey= 2; + kmi->oskey= 2; } /* if item was added, then bail out */ void WM_keymap_verify_item(ListBase *lb, char *idname, short type, short val, int modifier, short keymodifier) { - wmKeymapItem *km; + wmKeymapItem *kmi; - for(km= lb->first; km; km= km->next) - if(strncmp(km->idname, idname, OP_MAX_TYPENAME)==0) + for(kmi= lb->first; kmi; kmi= kmi->next) + if(strncmp(kmi->idname, idname, OP_MAX_TYPENAME)==0) break; - if(km==NULL) { - km= MEM_callocN(sizeof(wmKeymapItem), "keymap entry"); + if(kmi==NULL) { + kmi= MEM_callocN(sizeof(wmKeymapItem), "keymap entry"); - BLI_addtail(lb, km); - BLI_strncpy(km->idname, idname, OP_MAX_TYPENAME); + BLI_addtail(lb, kmi); + BLI_strncpy(kmi->idname, idname, OP_MAX_TYPENAME); - keymap_set(km, type, val, modifier, keymodifier); + keymap_set(kmi, type, val, modifier, keymodifier); } } @@ -93,30 +93,55 @@ void WM_keymap_verify_item(ListBase *lb, char *idname, short type, short val, in /* if item was added, then replace */ void WM_keymap_set_item(ListBase *lb, char *idname, short type, short val, int modifier, short keymodifier) { - wmKeymapItem *km; + wmKeymapItem *kmi; - for(km= lb->first; km; km= km->next) - if(strncmp(km->idname, idname, OP_MAX_TYPENAME)==0) + for(kmi= lb->first; kmi; kmi= kmi->next) + if(strncmp(kmi->idname, idname, OP_MAX_TYPENAME)==0) break; - if(km==NULL) { - km= MEM_callocN(sizeof(wmKeymapItem), "keymap entry"); + if(kmi==NULL) { + kmi= MEM_callocN(sizeof(wmKeymapItem), "keymap entry"); - BLI_addtail(lb, km); - BLI_strncpy(km->idname, idname, OP_MAX_TYPENAME); + BLI_addtail(lb, kmi); + BLI_strncpy(kmi->idname, idname, OP_MAX_TYPENAME); } - keymap_set(km, type, val, modifier, keymodifier); + keymap_set(kmi, type, val, modifier, keymodifier); } /* always add item */ void WM_keymap_add_item(ListBase *lb, char *idname, short type, short val, int modifier, short keymodifier) { - wmKeymapItem *km= MEM_callocN(sizeof(wmKeymapItem), "keymap entry"); + wmKeymapItem *kmi= MEM_callocN(sizeof(wmKeymapItem), "keymap entry"); - BLI_addtail(lb, km); - BLI_strncpy(km->idname, idname, OP_MAX_TYPENAME); + BLI_addtail(lb, kmi); + BLI_strncpy(kmi->idname, idname, OP_MAX_TYPENAME); - keymap_set(km, type, val, modifier, keymodifier); + keymap_set(kmi, type, val, modifier, keymodifier); } +/* ****************** storage in WM ************ */ + +/* name id's are for storing general or multiple keymaps, + space/region ids are same as DNA_space_types.h */ +/* gets free'd in wm.c */ + +ListBase *WM_keymap_listbase(wmWindowManager *wm, const char *nameid, int spaceid, int regionid) +{ + wmKeyMap *km; + + for(km= wm->keymaps.first; km; km= km->next) + if(km->spaceid==spaceid && km->regionid==regionid) + if(0==strncmp(nameid, km->nameid, KMAP_MAX_NAME)) + break; + if(km==NULL) { + km= MEM_callocN(sizeof(struct wmKeyMap), "keymap list"); + BLI_strncpy(km->nameid, nameid, KMAP_MAX_NAME); + km->spaceid= spaceid; + km->regionid= regionid; + printf("added keymap %s %d %d\n", nameid, spaceid, regionid); + BLI_addtail(&wm->keymaps, km); + } + + return &km->keymap; +} diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 17b248ae9ed..5dd36d737b1 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -352,10 +352,12 @@ void wm_operatortype_init(void) /* default keymap for windows and screens, only call once per WM */ void wm_window_keymap(wmWindowManager *wm) { + ListBase *keymap= WM_keymap_listbase(wm, "Window", 0, 0); + /* note, this doesn't replace existing keymap items */ - WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_window_duplicate", AKEY, KM_PRESS, KM_CTRL|KM_ALT, 0); - WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_window_fullscreen_toggle", FKEY, KM_PRESS, 0, 0); - WM_keymap_verify_item(&wm->windowkeymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_verify_item(keymap, "WM_OT_window_duplicate", AKEY, KM_PRESS, KM_CTRL|KM_ALT, 0); + WM_keymap_verify_item(keymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_verify_item(keymap, "WM_OT_window_fullscreen_toggle", FKEY, KM_PRESS, 0, 0); + WM_keymap_verify_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0); } diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 884abc1fa25..508fe21b039 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -190,6 +190,7 @@ static void wm_window_add_ghostwindow(wmWindowManager *wm, char *title, wmWindow 0 /* no stereo */); if (ghostwin) { + ListBase *keymap; win->ghostwin= ghostwin; GHOST_SetWindowUserData(ghostwin, win); /* pointer back */ @@ -197,9 +198,12 @@ static void wm_window_add_ghostwindow(wmWindowManager *wm, char *title, wmWindow if(win->eventstate==NULL) win->eventstate= MEM_callocN(sizeof(wmEvent), "window event state"); - /* add keymap handlers (1 for all keys in map!) */ - WM_event_add_keymap_handler(&win->handlers, &wm->windowkeymap); - WM_event_add_keymap_handler(&win->handlers, &wm->screenkeymap); + /* add keymap handlers (1 handler for all keys in map!) */ + keymap= WM_keymap_listbase(wm, "Window", 0, 0); + WM_event_add_keymap_handler(&win->handlers, keymap); + + keymap= WM_keymap_listbase(wm, "Screen", 0, 0); + WM_event_add_keymap_handler(&win->handlers, keymap); /* until screens get drawn, make it nice grey */ glClearColor(.55, .55, .55, 0.0); diff --git a/source/blender/windowmanager/wm_event_system.h b/source/blender/windowmanager/wm_event_system.h index 1b3b7ce8efb..0c37c56778f 100644 --- a/source/blender/windowmanager/wm_event_system.h +++ b/source/blender/windowmanager/wm_event_system.h @@ -66,11 +66,12 @@ enum { }; +/* wm_event_system.c */ void wm_event_add(wmWindow *win, wmEvent *event_to_add); void wm_event_free_all (wmWindow *win); wmEvent *wm_event_next (wmWindow *win); -/* goes over entire hierarchy: events -> window -> screen -> area -> region */ + /* goes over entire hierarchy: events -> window -> screen -> area -> region */ void wm_event_do_handlers (bContext *C); void wm_event_add_ghostevent(wmWindow *win, int type, void *customdata); @@ -78,5 +79,8 @@ void wm_event_add_ghostevent(wmWindow *win, int type, void *customdata); void wm_event_do_notifiers (bContext *C); void wm_draw_update (bContext *C); +/* wm_keymap.c */ + + #endif /* WM_EVENT_SYSTEM_H */ |