2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2007 Blender Foundation.
19 * All rights reserved.
22 * Contributor(s): Blender Foundation
24 * ***** END GPL LICENSE BLOCK *****
32 * \page wmpage windowmanager
33 * \section wmabout About windowmanager
34 * \ref wm handles events received from \ref GHOST and manages
35 * the screens, areas and input for Blender
36 * \section wmnote NOTE
40 /* dna-savable wmStructs here */
41 #include "DNA_windowmanager_types.h"
42 #include "WM_keymap.h"
51 struct wmEventHandler;
55 struct wmOperatorType;
60 struct EnumPropertyItem;
66 typedef struct wmJob wmJob;
69 void WM_init_state_size_set (int stax, int stay, int sizx, int sizy);
70 void WM_init_state_fullscreen_set(void);
71 void WM_init_state_normal_set(void);
72 void WM_init_native_pixels(int do_it);
74 void WM_init (struct bContext *C, int argc, const char **argv);
75 void WM_exit_ext (struct bContext *C, const short do_python);
77 void WM_exit (struct bContext *C)
78 #if defined(__GNUC__) || defined(__clang__)
79 __attribute__((noreturn))
83 void WM_main (struct bContext *C)
84 #if defined(__GNUC__) || defined(__clang__)
85 __attribute__((noreturn))
89 int WM_init_game (struct bContext *C);
90 void WM_init_splash (struct bContext *C);
93 void WM_check (struct bContext *C);
95 struct wmWindow *WM_window_open (struct bContext *C, struct rcti *rect);
97 int WM_window_pixels_x (struct wmWindow *win);
98 int WM_window_pixels_y (struct wmWindow *win);
100 /* defines for 'type' WM_window_open_temp */
101 #define WM_WINDOW_RENDER 0
102 #define WM_WINDOW_USERPREFS 1
103 #define WM_WINDOW_FILESEL 2
105 void WM_window_open_temp (struct bContext *C, struct rcti *position, int type);
107 /* returns true if draw method is triple buffer */
108 int WM_is_draw_triple(struct wmWindow *win);
113 void WM_file_read(struct bContext *C, const char *filepath, struct ReportList *reports);
114 void WM_autosave_init(struct wmWindowManager *wm);
117 void WM_cursor_set (struct wmWindow *win, int curs);
118 void WM_cursor_modal (struct wmWindow *win, int curs);
119 void WM_cursor_restore (struct wmWindow *win);
120 void WM_cursor_wait (int val);
121 void WM_cursor_grab_enable(struct wmWindow *win, int wrap, int hide, int bounds[4]);
122 void WM_cursor_grab_disable(struct wmWindow *win, int mouse_ungrab_xy[2]);
123 void WM_cursor_time (struct wmWindow *win, int nr);
125 void *WM_paint_cursor_activate(struct wmWindowManager *wm,
126 int (*poll)(struct bContext *C),
127 void (*draw)(struct bContext *C, int, int, void *customdata),
130 void WM_paint_cursor_end(struct wmWindowManager *wm, void *handle);
132 void WM_cursor_warp (struct wmWindow *win, int x, int y);
135 int WM_userdef_event_map(int kmitype);
139 struct wmEventHandler *WM_event_add_keymap_handler(ListBase *handlers, wmKeyMap *keymap);
140 /* boundbox, optional subwindow boundbox for offset */
141 struct wmEventHandler *WM_event_add_keymap_handler_bb(ListBase *handlers, wmKeyMap *keymap, rcti *bb, rcti *swinbb);
142 /* priority not implemented, it adds in begin */
143 struct wmEventHandler *WM_event_add_keymap_handler_priority(ListBase *handlers, wmKeyMap *keymap, int priority);
145 void WM_event_remove_keymap_handler(ListBase *handlers, wmKeyMap *keymap);
147 struct wmEventHandler *WM_event_add_ui_handler(const struct bContext *C, ListBase *handlers,
148 int (*func)(struct bContext *C, struct wmEvent *event, void *userdata),
149 void (*remove)(struct bContext *C, void *userdata), void *userdata);
150 void WM_event_remove_ui_handler(ListBase *handlers,
151 int (*func)(struct bContext *C, struct wmEvent *event, void *userdata),
152 void (*remove)(struct bContext *C, void *userdata),
153 void *userdata, int postpone);
154 void WM_event_remove_area_handler(struct ListBase *handlers, void *area);
156 struct wmEventHandler *WM_event_add_modal_handler(struct bContext *C, struct wmOperator *op);
157 void WM_event_remove_handlers(struct bContext *C, ListBase *handlers);
159 struct wmEventHandler *WM_event_add_dropbox_handler(ListBase *handlers, ListBase *dropboxes);
162 void WM_event_add_mousemove(struct bContext *C);
163 void WM_event_add_mousemove_window(struct wmWindow *window);
164 int WM_modal_tweak_exit(struct wmEvent *evt, int tweak_event);
167 void WM_event_add_notifier(const struct bContext *C, unsigned int type, void *reference);
168 void WM_main_add_notifier(unsigned int type, void *reference);
170 void wm_event_add (struct wmWindow *win, struct wmEvent *event_to_add); /* XXX only for warning */
172 /* at maximum, every timestep seconds it triggers event_type events */
173 struct wmTimer *WM_event_add_timer(struct wmWindowManager *wm, struct wmWindow *win, int event_type, double timestep);
174 void WM_event_remove_timer(struct wmWindowManager *wm, struct wmWindow *win, struct wmTimer *timer);
175 void WM_event_timer_sleep(struct wmWindowManager *wm, struct wmWindow *win, struct wmTimer *timer, int dosleep);
177 /* operator api, default callbacks */
178 /* invoke callback, uses enum property named "type" */
179 int WM_operator_view3d_distance_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
180 int WM_menu_invoke (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
181 int WM_enum_search_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
182 /* invoke callback, confirm menu + exec */
183 int WM_operator_confirm (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
184 /* invoke callback, file selector "filepath" unset + exec */
185 int WM_operator_filesel (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
186 int WM_operator_filesel_ensure_ext_imtype(wmOperator *op, const char imtype);
187 /* poll callback, context checks */
188 int WM_operator_winactive (struct bContext *C);
189 /* invoke callback, exec + redo popup */
190 int WM_operator_props_popup_call(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
191 int WM_operator_props_popup (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
192 int WM_operator_props_dialog_popup (struct bContext *C, struct wmOperator *op, int width, int height);
193 int WM_operator_redo_popup (struct bContext *C, struct wmOperator *op);
194 int WM_operator_ui_popup (struct bContext *C, struct wmOperator *op, int width, int height);
196 int WM_operator_confirm_message(struct bContext *C, struct wmOperator *op, const char *message);
199 void WM_operator_free (struct wmOperator *op);
200 void WM_operator_stack_clear(struct wmWindowManager *wm);
202 struct wmOperatorType *WM_operatortype_find(const char *idnamem, int quiet);
203 struct GHashIterator *WM_operatortype_iter(void);
204 void WM_operatortype_append (void (*opfunc)(struct wmOperatorType*));
205 void WM_operatortype_append_ptr (void (*opfunc)(struct wmOperatorType*, void *), void *userdata);
206 void WM_operatortype_append_macro_ptr (void (*opfunc)(struct wmOperatorType*, void *), void *userdata);
207 int WM_operatortype_remove(const char *idname);
209 struct wmOperatorType *WM_operatortype_append_macro(const char *idname, const char *name, const char *description, int flag);
210 struct wmOperatorTypeMacro *WM_operatortype_macro_define(struct wmOperatorType *ot, const char *idname);
213 int WM_operator_poll (struct bContext *C, struct wmOperatorType *ot);
214 int WM_operator_poll_context(struct bContext *C, struct wmOperatorType *ot, short context);
215 int WM_operator_call (struct bContext *C, struct wmOperator *op);
216 int WM_operator_call_notest(struct bContext *C, struct wmOperator *op);
217 int WM_operator_repeat (struct bContext *C, struct wmOperator *op);
218 int WM_operator_repeat_check(const struct bContext *C, struct wmOperator *op);
219 int WM_operator_name_call (struct bContext *C, const char *opstring, short context, struct PointerRNA *properties);
220 int WM_operator_call_py(struct bContext *C, struct wmOperatorType *ot, short context, struct PointerRNA *properties, struct ReportList *reports, short is_undo);
222 void WM_operator_properties_alloc(struct PointerRNA **ptr, struct IDProperty **properties, const char *opstring); /* used for keymap and macro items */
223 void WM_operator_properties_sanitize(struct PointerRNA *ptr, const short no_context); /* make props context sensitive or not */
224 int WM_operator_properties_default(struct PointerRNA *ptr, const int do_update);
225 void WM_operator_properties_reset(struct wmOperator *op);
226 void WM_operator_properties_create(struct PointerRNA *ptr, const char *opstring);
227 void WM_operator_properties_create_ptr(struct PointerRNA *ptr, struct wmOperatorType *ot);
228 void WM_operator_properties_free(struct PointerRNA *ptr);
229 void WM_operator_properties_filesel(struct wmOperatorType *ot, int filter, short type, short action, short flag, short display);
230 void WM_operator_properties_border(struct wmOperatorType *ot);
231 void WM_operator_properties_border_to_rcti(struct wmOperator *op, struct rcti *rect);
232 void WM_operator_properties_gesture_border(struct wmOperatorType *ot, int extend);
233 void WM_operator_properties_mouse_select(struct wmOperatorType *ot);
234 void WM_operator_properties_gesture_straightline(struct wmOperatorType *ot, int cursor);
235 void WM_operator_properties_select_all(struct wmOperatorType *ot);
237 int WM_operator_check_ui_enabled(const struct bContext *C, const char *idname);
238 wmOperator *WM_operator_last_redo(const struct bContext *C);
240 int WM_operator_last_properties_init(struct wmOperator *op);
241 int WM_operator_last_properties_store(struct wmOperator *op);
243 /* MOVE THIS SOMEWHERE ELSE */
246 #define SEL_DESELECT 2
250 /* flags for WM_operator_properties_filesel */
251 #define WM_FILESEL_RELPATH (1 << 0)
253 #define WM_FILESEL_DIRECTORY (1 << 1)
254 #define WM_FILESEL_FILENAME (1 << 2)
255 #define WM_FILESEL_FILEPATH (1 << 3)
256 #define WM_FILESEL_FILES (1 << 4)
259 /* operator as a python command (resultuing string must be freed) */
260 char *WM_operator_pystring(struct bContext *C, struct wmOperatorType *ot, struct PointerRNA *opptr, int all_args);
261 char *WM_prop_pystring(struct PointerRNA *ptr, struct PropertyRNA *prop, int index);
262 char *WM_prop_pystring_assign(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, int index);
263 void WM_operator_bl_idname(char *to, const char *from);
264 void WM_operator_py_idname(char *to, const char *from);
266 /* *************** menu types ******************** */
267 void WM_menutype_init(void);
268 struct MenuType *WM_menutype_find(const char *idname, int quiet);
269 int WM_menutype_add(struct MenuType *mt);
270 void WM_menutype_freelink(struct MenuType *mt);
271 void WM_menutype_free(void);
273 /* default operator callbacks for border/circle/lasso */
274 int WM_border_select_invoke (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
275 int WM_border_select_modal (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
276 int WM_border_select_cancel(struct bContext *C, struct wmOperator *op);
277 int WM_gesture_circle_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
278 int WM_gesture_circle_modal(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
279 int WM_gesture_circle_cancel(struct bContext *C, struct wmOperator *op);
280 int WM_gesture_lines_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
281 int WM_gesture_lines_modal(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
282 int WM_gesture_lines_cancel(struct bContext *C, struct wmOperator *op);
283 int WM_gesture_lasso_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
284 int WM_gesture_lasso_modal(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
285 int WM_gesture_lasso_cancel(struct bContext *C, struct wmOperator *op);
286 const int (*WM_gesture_lasso_path_to_array(struct bContext *C, struct wmOperator *op, int *mcords_tot))[2];
287 int WM_gesture_straightline_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
288 int WM_gesture_straightline_modal(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
289 int WM_gesture_straightline_cancel(struct bContext *C, struct wmOperator *op);
291 /* Gesture manager API */
292 struct wmGesture *WM_gesture_new(struct bContext *C, struct wmEvent *event, int type);
293 void WM_gesture_end(struct bContext *C, struct wmGesture *gesture);
294 void WM_gestures_remove(struct bContext *C);
296 /* fileselecting support */
297 void WM_event_add_fileselect(struct bContext *C, struct wmOperator *op);
298 void WM_event_fileselect_event(struct bContext *C, void *ophandle, int eventval);
300 void WM_event_print(struct wmEvent *event);
304 struct wmDrag *WM_event_start_drag(struct bContext *C, int icon, int type, void *poin, double value);
305 void WM_event_drag_image(struct wmDrag *, struct ImBuf *, float scale, int sx, int sy);
307 struct wmDropBox *WM_dropbox_add(ListBase *lb, const char *idname, int (*poll)(struct bContext *, struct wmDrag *, struct wmEvent *event),
308 void (*copy)(struct wmDrag *, struct wmDropBox *));
309 ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid);
311 /* Set a subwindow active in pixelspace view, with optional scissor subset */
312 void wmSubWindowSet (struct wmWindow *win, int swinid);
313 void wmSubWindowScissorSet (struct wmWindow *win, int swinid, struct rcti *srct);
315 /* OpenGL utilities with safety check + working in modelview matrix mode */
316 void wmFrustum (float x1, float x2, float y1, float y2, float n, float f);
317 void wmOrtho (float x1, float x2, float y1, float y2, float n, float f);
318 void wmOrtho2 (float x1, float x2, float y1, float y2);
321 void WM_framebuffer_index_set(int index);
322 int WM_framebuffer_to_index(unsigned int col);
324 /* threaded Jobs Manager */
326 WM_JOB_PRIORITY = (1 << 0),
327 WM_JOB_EXCL_RENDER = (1 << 1),
328 WM_JOB_PROGRESS = (1 << 2),
329 WM_JOB_SUSPEND = (1 << 3)
332 /* identifying jobs by owner alone is unreliable, this isnt saved, order can change (keep 0 for 'any') */
335 WM_JOB_TYPE_COMPOSITE,
337 WM_JOB_TYPE_RENDER_PREVIEW, /* UI preview */
338 WM_JOB_TYPE_SCREENCAST,
339 WM_JOB_TYPE_OBJECT_SIM_OCEAN,
340 WM_JOB_TYPE_OBJECT_SIM_FLUID,
341 WM_JOB_TYPE_OBJECT_BAKE_TEXTURE,
342 WM_JOB_TYPE_FILESEL_THUMBNAIL,
343 WM_JOB_TYPE_CLIP_BUILD_PROXY,
344 WM_JOB_TYPE_CLIP_TRACK_MARKERS,
345 WM_JOB_TYPE_CLIP_SOLVE_CAMERA,
346 WM_JOB_TYPE_SEQ_BUILD_PROXY,
347 /* add as needed, screencast, seq proxy build
348 * if having hard coded values is a problem */
351 struct wmJob *WM_jobs_get(struct wmWindowManager *wm, struct wmWindow *win, void *owner, const char *name, int flag, int job_type);
353 int WM_jobs_test(struct wmWindowManager *wm, void *owner, int job_type);
354 float WM_jobs_progress(struct wmWindowManager *wm, void *owner);
355 char *WM_jobs_name(struct wmWindowManager *wm, void *owner);
357 int WM_jobs_is_running(struct wmJob *);
358 void *WM_jobs_customdata_get(struct wmJob *);
359 void WM_jobs_customdata_set(struct wmJob *, void *customdata, void (*free)(void *));
360 void WM_jobs_timer(struct wmJob *, double timestep, unsigned int note, unsigned int endnote);
361 void WM_jobs_callbacks(struct wmJob *,
362 void (*startjob)(void *, short *, short *, float *),
363 void (*initjob)(void *),
364 void (*update)(void *),
365 void (*endjob)(void *));
367 void WM_jobs_start(struct wmWindowManager *wm, struct wmJob *);
368 void WM_jobs_stop(struct wmWindowManager *wm, void *owner, void *startjob);
369 void WM_jobs_kill(struct wmWindowManager *wm, void *owner, void (*)(void *, short int *, short int *, float *));
370 void WM_jobs_kill_all(struct wmWindowManager *wm);
371 void WM_jobs_kill_all_except(struct wmWindowManager *wm, void *owner);
372 void WM_jobs_kill_type(struct wmWindowManager *wm, int job_type);
374 int WM_jobs_has_running(struct wmWindowManager *wm);
377 char *WM_clipboard_text_get(int selection);
378 void WM_clipboard_text_set(char *buf, int selection);
381 void WM_progress_set(struct wmWindow *win, float progress);
382 void WM_progress_clear(struct wmWindow *win);
384 /* Draw (for screenshot) */
385 void WM_redraw_windows(struct bContext *C);
387 void WM_main_playanim(int argc, const char **argv);
389 /* debugging only, convenience function to write on crash */
390 int write_crash_blend(void);
396 #endif /* __WM_API_H__ */