Beispiel #1
0
    def set_exclusive_mouse(self, exclusive=True):
        if self._exclusive_mouse == exclusive and \
                self._exclusive_mouse_focus == self._has_focus:
            return

        # Mouse: UsagePage = 1, Usage = 2
        raw_mouse = RAWINPUTDEVICE(0x01, 0x02, 0, None)
        if not exclusive:
            raw_mouse.dwFlags = RIDEV_REMOVE
            raw_mouse.hwndTarget = None

        if not _user32.RegisterRawInputDevices(byref(raw_mouse), 1,
                                               sizeof(RAWINPUTDEVICE)):
            if exclusive:
                raise WindowException("Cannot enter mouse exclusive mode.")

        self._exclusive_mouse_buttons = 0
        if exclusive and self._has_focus:
            self._update_clipped_cursor()
        else:
            # Release clip
            _user32.ClipCursor(None)

        self._exclusive_mouse = exclusive
        self._exclusive_mouse_focus = self._has_focus
        self.set_mouse_platform_visible(not exclusive)
    def dispatch_events(self):
        from pyglet import app
        app.platform_event_loop.dispatch_posted_events()

        self._allow_dispatch_event = True
        while self._event_queue:
            EventDispatcher.dispatch_event(self, *self._event_queue.pop(0))

        e = EventRef()
        result = carbon.ReceiveNextEvent(0, c_void_p(), 0, True, byref(e))
        while result == noErr:
            carbon.SendEventToEventTarget(e, self._event_dispatcher)
            carbon.ReleaseEvent(e)

            result = carbon.ReceiveNextEvent(0, c_void_p(), 0, True, byref(e))

        self._allow_dispatch_event = False

        # Return value from ReceiveNextEvent can be ignored if not
        # noErr; we check here only to look for new bugs.
        # eventLoopQuitErr: the inner event loop was quit, see
        # http://lists.apple.com/archives/Carbon-dev/2006/Jun/msg00850.html
        # Can occur when mixing with other toolkits, e.g. Tk.
        # Fixes issue 180.
        if result not in (eventLoopTimedOutErr, eventLoopQuitErr):
            raise WindowException('Error %d' % result)
 def set_size(self, width, height):
     if self._fullscreen:
         raise WindowException('Cannot set size of fullscreen window.')
     width, height = self._client_to_window_size(width, height)
     _user32.SetWindowPos(self._hwnd, 0, 0, 0, width, height,
                          (SWP_NOZORDER |
                           SWP_NOMOVE |
                           SWP_NOOWNERZORDER))
Beispiel #4
0
 def set_size(self, width, height):
     if self._fullscreen:
         raise WindowException('Cannot set size of fullscreen window.')
     self._width = width
     self._height = height
     if not self._resizable:
         self.set_minimum_size(width, height)
         self.set_maximum_size(width, height)
     xlib.XResizeWindow(self._x_display, self._window, width, height)
     self.dispatch_event('on_resize', width, height)
Beispiel #5
0
    def set_size(self, width, height):
        if self._fullscreen:
            raise WindowException('Cannot set size of fullscreen window.')
        rect = Rect()
        carbon.GetWindowBounds(self._window, kWindowContentRgn, byref(rect))
        rect.right = rect.left + width
        rect.bottom = rect.top + height
        carbon.SetWindowBounds(self._window, kWindowContentRgn, byref(rect))

        self._width = width
        self._height = height
        self.dispatch_event('on_resize', width, height)
        self.dispatch_event('on_expose')
Beispiel #6
0
 def set_size(self, width, height):
     if self._fullscreen:
         raise WindowException('Cannot set size of fullscreen window.')
     self._width = max(1, int(width))
     self._height = max(1, int(height))
     # Move frame origin down so that top-left corner of window doesn't move.
     rect = self._nswindow.contentRectForFrameRect_(self._nswindow.frame())
     rect.origin.y += rect.size.height - self._height
     rect.size.width = self._width
     rect.size.height = self._height
     frame = self._nswindow.frameRectForContentRect_(rect)
     # The window background flashes when the frame size changes unless it's
     # animated, but we can set the window's animationResizeTime to zero.
     self._nswindow.setFrame_display_animate_(frame, True, self._nswindow.isVisible())
Beispiel #7
0
    def set_exclusive_mouse(self, exclusive=True):
        if self._exclusive_mouse == exclusive and \
           self._exclusive_mouse_focus == self._has_focus:
            return

        # Mouse: UsagePage = 1, Usage = 2
        raw_mouse = RAWINPUTDEVICE(0x01, 0x02, 0, None)
        if exclusive:
            raw_mouse.dwFlags = RIDEV_NOLEGACY
            raw_mouse.hwndTarget = self._view_hwnd
        else:
            raw_mouse.dwFlags |= RIDEV_REMOVE
            raw_mouse.hwndTarget = None

        if not _user32.RegisterRawInputDevices(byref(raw_mouse), 1,
                                               sizeof(RAWINPUTDEVICE)):
            if exclusive:
                raise WindowException("Cannot enter mouse exclusive mode.")

        self._exclusive_mouse_buttons = 0
        if exclusive and self._has_focus:
            # Move mouse to the center of the window.
            self._reset_exclusive_mouse_screen()
            x, y = self._exclusive_mouse_screen
            self.set_mouse_position(x, y, absolute=True)

            # Clip to client area, to prevent large mouse movements taking
            # it outside the client area.
            rect = RECT()
            _user32.GetClientRect(self._view_hwnd, byref(rect))
            _user32.MapWindowPoints(self._view_hwnd, HWND_DESKTOP, byref(rect),
                                    2)
            _user32.ClipCursor(byref(rect))
        else:
            # Release clip
            _user32.ClipCursor(None)
            # Move mouse bak to the middle of the client area.
            if self._exclusive_mouse_screen:
                x, y = self._exclusive_mouse_screen
                self.set_mouse_position(x, y, absolute=True)

        self._exclusive_mouse = exclusive
        self._exclusive_mouse_focus = self._has_focus
        self.set_mouse_platform_visible(not exclusive)
Beispiel #8
0
    def set_size(self, width, height):
        if self._fullscreen:
            raise WindowException('Cannot set size of fullscreen window.')
        self._width = max(1, int(width))
        self._height = max(1, int(height))
        # Move frame origin down so that top-left corner of window doesn't move.
        window_frame = self._nswindow.frame()
        rect = self._nswindow.contentRectForFrameRect_(window_frame)
        rect.origin.y += rect.size.height - self._height
        rect.size.width = self._width
        rect.size.height = self._height
        new_frame = self._nswindow.frameRectForContentRect_(rect)
        # The window background flashes when the frame size changes unless it's
        # animated, but we can set the window's animationResizeTime to zero.
        is_visible = self._nswindow.isVisible()
        self._nswindow.setFrame_display_animate_(new_frame, True, is_visible)

        # See if we need to adjust for Retina not telling us the pixel size
        self._reset_to_actual_window_size()
Beispiel #9
0
    def set_exclusive_mouse(self, exclusive=True):
        if self._mouse_exclusive == exclusive and \
                self._exclusive_mouse_focus == self._has_focus:
            return

        # Mouse: UsagePage = 1, Usage = 2
        raw_mouse = RAWINPUTDEVICE(0x01, 0x02, 0, None)
        if exclusive:
            raw_mouse.dwFlags = RIDEV_NOLEGACY
            raw_mouse.hwndTarget = self._view_hwnd
        else:
            raw_mouse.dwFlags = RIDEV_REMOVE
            raw_mouse.hwndTarget = None

        if not _user32.RegisterRawInputDevices(byref(raw_mouse), 1,
                                               sizeof(RAWINPUTDEVICE)):
            if exclusive:
                raise WindowException("Cannot enter mouse exclusive mode.")

        self._exclusive_mouse_buttons = 0
        if exclusive and self._has_focus:
            # Clip to client area, to prevent large mouse movements taking
            # it outside the client area.
            rect = RECT()
            _user32.GetClientRect(self._view_hwnd, byref(rect))
            _user32.MapWindowPoints(self._view_hwnd, HWND_DESKTOP, byref(rect),
                                    2)
            _user32.ClipCursor(byref(rect))
            # Release mouse capture in case is was acquired during mouse click
            _user32.ReleaseCapture()
        else:
            # Release clip
            _user32.ClipCursor(None)

        super().set_exclusive_mouse(exclusive)
        self._exclusive_mouse_focus = self._has_focus
        self.set_mouse_platform_visible(not exclusive)