Exemple #1
0
static void wm_paintcursor_draw(bContext *C, ARegion *ar)
{
	wmWindowManager *wm = CTX_wm_manager(C);
	
	if (wm->paintcursors.first) {
		wmWindow *win = CTX_wm_window(C);
		bScreen *screen = win->screen;
		wmPaintCursor *pc;

		if (ar->swinid && screen->subwinactive == ar->swinid) {
			for (pc = wm->paintcursors.first; pc; pc = pc->next) {
				if (pc->poll == NULL || pc->poll(C)) {
					ARegion *ar_other = CTX_wm_region(C);
					if (ELEM(win->grabcursor, GHOST_kGrabWrap, GHOST_kGrabHide)) {
						int x = 0, y = 0;
						wm_get_cursor_position(win, &x, &y);
						pc->draw(C,
						         x - ar_other->winrct.xmin,
						         y - ar_other->winrct.ymin,
						         pc->customdata);
					}
					else {
						pc->draw(C,
						         win->eventstate->x - ar_other->winrct.xmin,
						         win->eventstate->y - ar_other->winrct.ymin,
						         pc->customdata);
					}
				}
			}
		}
	}
}
Exemple #2
0
static void wm_cursor_warp_relative(wmWindow *win, int x, int y)
{
	/* note: don't use wmEvent coords because of continuous grab [#36409] */
	int cx, cy;
	wm_get_cursor_position(win, &cx, &cy);
	WM_cursor_warp(win, cx + x, cy + y);
}
Exemple #3
0
static void wm_paintcursor_draw(bContext *C, ScrArea *sa, ARegion *ar)
{
  wmWindowManager *wm = CTX_wm_manager(C);
  wmWindow *win = CTX_wm_window(C);
  bScreen *screen = WM_window_get_active_screen(win);
  wmPaintCursor *pc;

  if (ar->visible && ar == screen->active_region) {
    for (pc = wm->paintcursors.first; pc; pc = pc->next) {

      if ((pc->space_type != SPACE_TYPE_ANY) && (sa->spacetype != pc->space_type)) {
        continue;
      }

      if ((pc->region_type != RGN_TYPE_ANY) && (ar->regiontype != pc->region_type)) {
        continue;
      }

      if (pc->poll == NULL || pc->poll(C)) {
        /* Prevent drawing outside region. */
        glEnable(GL_SCISSOR_TEST);
        glScissor(ar->winrct.xmin,
                  ar->winrct.ymin,
                  BLI_rcti_size_x(&ar->winrct) + 1,
                  BLI_rcti_size_y(&ar->winrct) + 1);

        if (ELEM(win->grabcursor, GHOST_kGrabWrap, GHOST_kGrabHide)) {
          int x = 0, y = 0;
          wm_get_cursor_position(win, &x, &y);
          pc->draw(C, x, y, pc->customdata);
        }
        else {
          pc->draw(C, win->eventstate->x, win->eventstate->y, pc->customdata);
        }

        glDisable(GL_SCISSOR_TEST);
      }
    }
  }
}
/* mouse coordinate converversion happens here */
static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr)
{
    bContext *C = C_void_ptr;
    wmWindowManager *wm = CTX_wm_manager(C);
    GHOST_TEventType type = GHOST_GetEventType(evt);
    int time = GHOST_GetEventTime(evt);

    if (type == GHOST_kEventQuit) {
        WM_exit(C);
    }
    else {
        GHOST_WindowHandle ghostwin = GHOST_GetEventWindow(evt);
        GHOST_TEventDataPtr data = GHOST_GetEventData(evt);
        wmWindow *win;

        /* Ghost now can call this function for life resizes, but it should return if WM didn't initialize yet.
         * Can happen on file read (especially full size window)  */
        if ((wm->initialized & WM_INIT_WINDOW) == 0) {
            return 1;
        }
        if (!ghostwin) {
            /* XXX - should be checked, why are we getting an event here, and */
            /* what is it? */
            puts("<!> event has no window");
            return 1;
        }
        else if (!GHOST_ValidWindow(g_system, ghostwin)) {
            /* XXX - should be checked, why are we getting an event here, and */
            /* what is it? */
            puts("<!> event has invalid window");
            return 1;
        }
        else {
            win = GHOST_GetWindowUserData(ghostwin);
        }

        switch (type) {
        case GHOST_kEventWindowDeactivate:
            wm_event_add_ghostevent(wm, win, type, time, data);
            win->active = 0; /* XXX */

            /* clear modifiers for inactive windows */
            win->eventstate->alt = 0;
            win->eventstate->ctrl = 0;
            win->eventstate->shift = 0;
            win->eventstate->oskey = 0;
            win->eventstate->keymodifier = 0;

            break;
        case GHOST_kEventWindowActivate:
        {
            GHOST_TEventKeyData kdata;
            wmEvent event;
            int wx, wy;
            const int keymodifier = ((query_qual(SHIFT)     ? KM_SHIFT : 0) |
                                     (query_qual(CONTROL)   ? KM_CTRL  : 0) |
                                     (query_qual(ALT)       ? KM_ALT   : 0) |
                                     (query_qual(OS)        ? KM_OSKEY : 0));

            /* Win23/GHOST modifier bug, see T40317 */
#ifndef WIN32
//#  define USE_WIN_ACTIVATE
#endif

            wm->winactive = win; /* no context change! c->wm->windrawable is drawable, or for area queues */

            win->active = 1;
//				window_handle(win, INPUTCHANGE, win->active);

            /* bad ghost support for modifier keys... so on activate we set the modifiers again */

            /* TODO: This is not correct since a modifier may be held when a window is activated...
             * better solve this at ghost level. attempted fix r54450 but it caused bug [#34255]
             *
             * For now don't send GHOST_kEventKeyDown events, just set the 'eventstate'.
             */
            kdata.ascii = '\0';
            kdata.utf8_buf[0] = '\0';

            if (win->eventstate->shift) {
                if ((keymodifier & KM_SHIFT) == 0) {
                    kdata.key = GHOST_kKeyLeftShift;
                    wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, time, &kdata);
                }
            }
#ifdef USE_WIN_ACTIVATE
            else {
                if (keymodifier & KM_SHIFT) {
                    win->eventstate->shift = KM_MOD_FIRST;
                }
            }
#endif
            if (win->eventstate->ctrl) {
                if ((keymodifier & KM_CTRL) == 0) {
                    kdata.key = GHOST_kKeyLeftControl;
                    wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, time, &kdata);
                }
            }
#ifdef USE_WIN_ACTIVATE
            else {
                if (keymodifier & KM_CTRL) {
                    win->eventstate->ctrl = KM_MOD_FIRST;
                }
            }
#endif
            if (win->eventstate->alt) {
                if ((keymodifier & KM_ALT) == 0) {
                    kdata.key = GHOST_kKeyLeftAlt;
                    wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, time, &kdata);
                }
            }
#ifdef USE_WIN_ACTIVATE
            else {
                if (keymodifier & KM_ALT) {
                    win->eventstate->alt = KM_MOD_FIRST;
                }
            }
#endif
            if (win->eventstate->oskey) {
                if ((keymodifier & KM_OSKEY) == 0) {
                    kdata.key = GHOST_kKeyOS;
                    wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, time, &kdata);
                }
            }
#ifdef USE_WIN_ACTIVATE
            else {
                if (keymodifier & KM_OSKEY) {
                    win->eventstate->oskey = KM_MOD_FIRST;
                }
            }
#endif

#undef USE_WIN_ACTIVATE


            /* keymodifier zero, it hangs on hotkeys that open windows otherwise */
            win->eventstate->keymodifier = 0;

            /* entering window, update mouse pos. but no event */
            wm_get_cursor_position(win,  &wx, &wy);

            win->eventstate->x = wx;
            win->eventstate->y = wy;

            win->addmousemove = 1;   /* enables highlighted buttons */

            wm_window_make_drawable(wm, win);

            /* window might be focused by mouse click in configuration of window manager
             * when focus is not following mouse
             * click could have been done on a button and depending on window manager settings
             * click would be passed to blender or not, but in any case button under cursor
             * should be activated, so at max next click on button without moving mouse
             * would trigger it's handle function
             * currently it seems to be common practice to generate new event for, but probably
             * we'll need utility function for this? (sergey)
             */
            wm_event_init_from_window(win, &event);
            event.type = MOUSEMOVE;
            event.prevx = event.x;
            event.prevy = event.y;

            wm_event_add(win, &event);

            break;
        }
        case GHOST_kEventWindowClose:
        {
            wm_window_close(C, wm, win);
            break;
        }
        case GHOST_kEventWindowUpdate:
        {
            if (G.debug & G_DEBUG_EVENTS) {
                printf("%s: ghost redraw %d\n", __func__, win->winid);
            }

            wm_window_make_drawable(wm, win);
            WM_event_add_notifier(C, NC_WINDOW, NULL);

            break;
        }
        case GHOST_kEventWindowSize:
        case GHOST_kEventWindowMove:
        {
            GHOST_TWindowState state;
            state = GHOST_GetWindowState(win->ghostwin);
            win->windowstate = state;

            /* stop screencast if resize */
            if (type == GHOST_kEventWindowSize) {
                WM_jobs_stop(wm, win->screen, NULL);
            }

            /* win32: gives undefined window size when minimized */
            if (state != GHOST_kWindowStateMinimized) {
                GHOST_RectangleHandle client_rect;
                int l, t, r, b, scr_w, scr_h;
                int sizex, sizey, posx, posy;

                client_rect = GHOST_GetClientBounds(win->ghostwin);
                GHOST_GetRectangle(client_rect, &l, &t, &r, &b);

                GHOST_DisposeRectangle(client_rect);

                wm_get_desktopsize(&scr_w, &scr_h);
                sizex = r - l;
                sizey = b - t;
                posx = l;
                posy = scr_h - t - win->sizey;

                /*
                 * Ghost sometimes send size or move events when the window hasn't changed.
                 * One case of this is using compiz on linux. To alleviate the problem
                 * we ignore all such event here.
                 *
                 * It might be good to eventually do that at Ghost level, but that is for
                 * another time.
                 */
                if (win->sizex != sizex ||
                        win->sizey != sizey ||
                        win->posx != posx ||
                        win->posy != posy)
                {
                    win->sizex = sizex;
                    win->sizey = sizey;
                    win->posx = posx;
                    win->posy = posy;

                    /* debug prints */
                    if (G.debug & G_DEBUG_EVENTS) {
                        const char *state_str;
                        state = GHOST_GetWindowState(win->ghostwin);

                        if (state == GHOST_kWindowStateNormal) {
                            state_str = "normal";
                        }
                        else if (state == GHOST_kWindowStateMinimized) {
                            state_str = "minimized";
                        }
                        else if (state == GHOST_kWindowStateMaximized) {
                            state_str = "maximized";
                        }
                        else if (state == GHOST_kWindowStateFullScreen) {
                            state_str = "fullscreen";
                        }
                        else {
                            state_str = "<unknown>";
                        }

                        printf("%s: window %d state = %s\n", __func__, win->winid, state_str);

                        if (type != GHOST_kEventWindowSize) {
                            printf("win move event pos %d %d size %d %d\n",
                                   win->posx, win->posy, win->sizex, win->sizey);
                        }
                    }

                    wm_window_make_drawable(wm, win);
                    wm_draw_window_clear(win);
                    WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
                    WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, NULL);

#if defined(__APPLE__) || defined(WIN32)
                    /* OSX and Win32 don't return to the mainloop while resize */
                    wm_event_do_handlers(C);
                    wm_event_do_notifiers(C);
                    wm_draw_update(C);
#endif
                }
            }
            break;
        }

        case GHOST_kEventOpenMainFile:
        {
            PointerRNA props_ptr;
            wmWindow *oldWindow;
            const char *path = GHOST_GetEventData(evt);

            if (path) {
                wmOperatorType *ot = WM_operatortype_find("WM_OT_open_mainfile", false);
                /* operator needs a valid window in context, ensures
                 * it is correctly set */
                oldWindow = CTX_wm_window(C);
                CTX_wm_window_set(C, win);

                WM_operator_properties_create_ptr(&props_ptr, ot);
                RNA_string_set(&props_ptr, "filepath", path);
                WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &props_ptr);
                WM_operator_properties_free(&props_ptr);

                CTX_wm_window_set(C, oldWindow);
            }
            break;
        }
        case GHOST_kEventDraggingDropDone:
        {
            wmEvent event;
            GHOST_TEventDragnDropData *ddd = GHOST_GetEventData(evt);
            int wx, wy;

            /* entering window, update mouse pos */
            wm_get_cursor_position(win, &wx, &wy);
            win->eventstate->x = wx;
            win->eventstate->y = wy;

            wm_event_init_from_window(win, &event);  /* copy last state, like mouse coords */

            /* activate region */
            event.type = MOUSEMOVE;
            event.prevx = event.x;
            event.prevy = event.y;

            wm->winactive = win; /* no context change! c->wm->windrawable is drawable, or for area queues */
            win->active = 1;

            wm_event_add(win, &event);


            /* make blender drop event with custom data pointing to wm drags */
            event.type = EVT_DROP;
            event.val = KM_RELEASE;
            event.custom = EVT_DATA_DRAGDROP;
            event.customdata = &wm->drags;
            event.customdatafree = 1;

            wm_event_add(win, &event);

            /* printf("Drop detected\n"); */

            /* add drag data to wm for paths: */

            if (ddd->dataType == GHOST_kDragnDropTypeFilenames) {
                GHOST_TStringArray *stra = ddd->data;
                int a, icon;

                for (a = 0; a < stra->count; a++) {
                    printf("drop file %s\n", stra->strings[a]);
                    /* try to get icon type from extension */
                    icon = ED_file_extension_icon((char *)stra->strings[a]);

                    WM_event_start_drag(C, icon, WM_DRAG_PATH, stra->strings[a], 0.0, WM_DRAG_NOP);
                    /* void poin should point to string, it makes a copy */
                    break; /* only one drop element supported now */
                }
            }

            break;
        }
        case GHOST_kEventNativeResolutionChange:
            // printf("change, pixel size %f\n", GHOST_GetNativePixelSize(win->ghostwin));

            U.pixelsize = wm_window_pixelsize(win);
            BKE_userdef_state();
            WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
            WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, NULL);

            break;
        case GHOST_kEventTrackpad:
        {
            GHOST_TEventTrackpadData *pd = data;

            wm_convert_cursor_position(win, &pd->x, &pd->y);
            wm_event_add_ghostevent(wm, win, type, time, data);
            break;
        }
        case GHOST_kEventCursorMove:
        {
            GHOST_TEventCursorData *cd = data;

            wm_convert_cursor_position(win, &cd->x, &cd->y);
            wm_event_add_ghostevent(wm, win, type, time, data);
            break;
        }
        default:
            wm_event_add_ghostevent(wm, win, type, time, data);
            break;
        }

    }
    return 1;
}