xpra icon
Bug tracker and wiki

Ticket #1321: osx-shadow-scrolling-v2.patch

File osx-shadow-scrolling-v2.patch, 5.6 KB (added by Antoine Martin, 3 months ago)

updated patch

  • xpra/platform/darwin/shadow_server.py

     
    8080            raise InitExit(1, "cannot grab pixels from the screen, make sure this command is launched from a GUI session")
    8181        patch_picture_encode()
    8282        self.refresh_count = 0
     83        self.move_count = 0
     84        self.move_rectangle_count = 0
     85        self.move_registered = False
    8386        self.refresh_rectangle_count = 0
    8487        self.refresh_registered = False
    8588        GTKShadowServerBase.__init__(self)
     
    98101        return GTKStatusIconTray(self, 0, self.tray, "Xpra Shadow Server", None, None,
    99102                                 self.tray_click_callback, mouseover_cb=None, exit_cb=self.tray_exit_callback)
    100103
    101 
    102104    def setup_capture(self):
    103105        return OSXRootCapture()
    104106
    105     def screen_refresh_callback(self, count, rects, info):
    106         log("screen_refresh_callback%s mapped=%s", (count, rects, info), self.mapped)
    107         self.refresh_count += 1
     107    def _cgrects_to_list(self, count, rects):
    108108        rlist = []
    109         for r in rects:
     109        for i in range(count):
     110            r = rects[i]
    110111            if not isinstance(r, CG.CGRect):
    111                 log.error("Error: invalid rectangle in refresh list: %s", r)
     112                log.error("Error: invalid rectangle in refresh list: %s (%s)", r, type(r))
    112113                continue
    113114            self.refresh_rectangle_count += 1
    114115            rlist.append((int(r.origin.x), int(r.origin.y), int(r.size.width), int(r.size.height)))
     116        return rlist
     117
     118    def screen_move_callback(self, delta, count, rects, info):
     119        log.info("screen_move_callback%s mapped=%s", (delta, count, rects, info), self.mapped)
     120        self.move_count += 1
     121        rlist = self._cgrects_to_list(count, rects)
     122        self.move_rectangle_count += len(rlist)
     123        self.idle_add(self.do_screen_move, delta, rlist)
     124
     125    def do_screen_move(self, delta, rlist):
     126        log.info("do_screen_move%s", (delta, rlist))
     127
     128    def screen_refresh_callback(self, count, rects, info):
     129        log("screen_refresh_callback%s mapped=%s", (count, rects, info), self.mapped)
     130        self.refresh_count += 1
     131        rlist = self._cgrects_to_list(count, rects)
    115132        #return quickly, and process the list copy via idle add:
    116133        self.idle_add(self.do_screen_refresh, rlist)
    117134
     
    139156        if not USE_TIMER:
    140157            err = CG.CGRegisterScreenRefreshCallback(self.screen_refresh_callback, None)
    141158            log("CGRegisterScreenRefreshCallback(%s)=%s", self.screen_refresh_callback, err)
    142             if err==0:
    143                 self.refresh_registered = True
     159            self.refresh_registered = err==0
     160            if self.refresh_registered:
     161                #now try to register move callback (optional):
     162                try:
     163                    err = CG.CGScreenRegisterMoveCallback(self.screen_move_callback, None)
     164                    log("CGScreenRegisterMoveCallback(%s)=%s", self.screen_move_callback, err)
     165                except Exception as e:
     166                    err = str(e)
     167                self.move_registered = err==0
     168                if not self.move_registered:
     169                    log.warn("Warning: CGScreenRegisterMoveCallback failed with error %i", err)
     170                    log.warn(" no scrolling detection")
    144171                return
    145172            log.warn("Warning: CGRegisterScreenRefreshCallback failed with error %i", err)
    146173            log.warn(" using fallback timer method")
     
    150177        log("stop_refresh(%i) mapped=%s, timer=%s", wid, self.mapped, self.refresh_timer)
    151178        #may stop the timer fallback:
    152179        super().stop_refresh(wid)
    153         if self.refresh_registered and not self.mapped:
     180        if self.mapped:
     181            return
     182        if self.refresh_registered:
    154183            try:
    155184                err = CG.CGUnregisterScreenRefreshCallback(self.screen_refresh_callback, None)
    156185                log("CGUnregisterScreenRefreshCallback(%s)=%s", self.screen_refresh_callback, err)
     
    160189                log.warn("Error unregistering screen refresh callback:")
    161190                log.warn(" %s", e)
    162191            self.refresh_registered = False
     192        if self.move_registered:
     193            try:
     194                err = CG.CGScreenUnregisterMoveCallback(self.screen_move_callback, None)
     195                log("CGScreenUnregisterMoveCallback(%s)=%s", self.screen_move_callback, err)
     196                if err:
     197                    log.warn(" unregistering the move callback returned %s", err)
     198            except ValueError as e:
     199                log.warn("Error unregistering screen refresh callback:")
     200                log.warn(" %s", e)
     201            self.move_registered = False
    163202
    164 
    165     def do_process_mouse_common(self, proto, wid, pointer, *args):
     203    def do_process_mouse_common(self, proto, wid, pointer, *_args):
    166204        assert proto in self._server_sources
    167205        assert wid in self._id_to_window
    168206        CG.CGWarpMouseCursorPosition(pointer[:2])
     
    223261                                              "notifications"   : self.refresh_registered,
    224262                                              "count"           : self.refresh_count,
    225263                                              "rectangles"      : self.refresh_rectangle_count,
     264                                              "move"            : self.move_count,
     265                                              "move-rectangles" : self.move_rectangle_count,
    226266                                              })
    227267        return info
    228268