xpra icon
Bug tracker and wiki

Ticket #490: focus-force-transientfor.patch

File focus-force-transientfor.patch, 8.7 KB (added by Antoine Martin, 6 years ago)

patch including all the different changes that were tested - works!

  • xpra/client/client_base.py

     
    470470            packet_type = packet[0]
    471471            if type(packet_type)==int:
    472472                packet_type = self._aliases.get(packet_type)
     473            log.info("processing packet %s", packet_type)
    473474            handler = self._packet_handlers.get(packet_type)
    474475            if handler:
    475476                handler(packet)
  • xpra/client/client_window_base.py

     
    2828class ClientWindowBase(ClientWidgetBase):
    2929
    3030    def __init__(self, client, group_leader, wid, x, y, w, h, metadata, override_redirect, client_properties, auto_refresh_delay):
    31         log.debug("%s%s", type(self), (client, group_leader, wid, x, y, w, h, metadata, override_redirect, client_properties, auto_refresh_delay))
     31        log.info("%s%s", type(self), (client, group_leader, wid, x, y, w, h, metadata, override_redirect, client_properties, auto_refresh_delay))
    3232        ClientWidgetBase.__init__(self, client, wid)
    3333        self._override_redirect = override_redirect
    3434        self.group_leader = group_leader
     
    330330        if pressed_state is False and depressed is False:
    331331            #we're getting a mouse-up event for this window but we never got
    332332            #the mouse-down event, so simulate one (needed for some dialogs on win32):
     333            log.info("simulating mouse down!")
    333334            send_button(True)
    334335        self.button_state[button] = depressed
    335336        send_button(depressed)
  • xpra/client/gtk_base/gtk_client_window_base.py

     
    6363            type_hint = self.get_type_hint()
    6464            if transient_for is not None and transient_for.window is not None and type_hint in self.OR_TYPE_HINTS:
    6565                transient_for._override_redirect_windows.append(self)
    66         if not self._override_redirect:
    67             self.connect("notify::has-toplevel-focus", self._focus_change)
     66        self.connect("notify::has-toplevel-focus", self._focus_change)
    6867        def focus_in(*args):
    69             self.debug("focus-in-event for wid=%s", self._id)
     68            self.info("focus-in-event for wid=%s", self._id)
    7069        def focus_out(*args):
    71             self.debug("focus-out-event for wid=%s", self._id)
     70            self.info("focus-out-event for wid=%s", self._id)
    7271        self.connect("focus-in-event", focus_in)
    7372        self.connect("focus-out-event", focus_out)
    7473        if self._can_set_workspace:
     
    9089        self._fullscreen = bool(event.new_window_state & self.WINDOW_STATE_FULLSCREEN)
    9190        maximized = bool(event.new_window_state & self.WINDOW_STATE_MAXIMIZED)
    9291        self._client_properties["maximized"] = maximized
    93         self.debug("window_state_updated(%s, %s) new_window_state=%s, fullscreen=%s, maximized=%s", widget, repr(event), event.new_window_state, self._fullscreen, maximized)
     92        self.info("window_state_updated(%s, %s) wid=%s, new_window_state=%s, fullscreen=%s, maximized=%s", widget, repr(event), self._id, event.new_window_state, self._fullscreen, maximized)
     93        if self._override_redirect:
     94            self.info("force raising")
     95            self.present()
    9496
    9597    def set_fullscreen(self, fullscreen):
    9698        if self._fullscreen is None or self._fullscreen!=fullscreen:
     
    365367    def _focus_change(self, *args):
    366368        assert not self._override_redirect
    367369        htf = self.get_property("has-toplevel-focus")
    368         self.debug("_focus_change(%s) wid=%s, has-toplevel-focus=%s, _been_mapped=%s", args, self._id, htf, self._been_mapped)
    369         if self._been_mapped:
     370        self.info("_focus_change(%s) wid=%s, has-toplevel-focus=%s, _been_mapped=%s", args, self._id, htf, self._been_mapped)
     371        if self._been_mapped and not self._override_redirect:
    370372            self._client.update_focus(self._id, htf)
  • xpra/client/ui_client_base.py

     
    190190
    191191        #state:
    192192        self._focused = None
     193        self._or_focused = None
    193194
    194195        self.init_packet_handlers()
    195196        self.init_aliases()
     
    600601
    601602
    602603    def send_focus(self, wid):
    603         log("send_focus(%s)", wid)
     604        log.info("send_focus(%s)", wid)
    604605        self.send("focus", wid, self.get_current_modifiers())
    605606
    606607    def update_focus(self, wid, gotit):
    607         log("update_focus(%s, %s) _focused=%s", wid, gotit, self._focused)
     608        log.info("update_focus(%s, %s) _focused=%s", wid, gotit, self._focused)
     609        #special handling for when we have an OR window with the focus:
     610        if self._or_focused is not None:
     611            if not gotit and wid!=self._or_focused:
     612                #a window which is not the OR window lost focus,
     613                #ignore it
     614                log.info("ignoring non-OR window losing focus")
     615                return
     616            log.info("clearing OR focus")
     617            self._or_focused = None
    608618        if gotit and self._focused is not wid:
    609619            if self.keyboard_helper:
    610620                self.keyboard_helper.clear_repeat()
     
    14301440    def make_new_window(self, wid, x, y, w, h, metadata, override_redirect, client_properties, auto_refresh_delay):
    14311441        client_window_classes = self.get_client_window_classes(metadata, override_redirect)
    14321442        group_leader_window = self.get_group_leader(metadata, override_redirect)
     1443
     1444        log.info("make_new_window: pid=%s, window-type=%s, transient-for=%s", metadata.get("pid"), metadata.get("window-type"), metadata.get("transient-for"))
     1445        if override_redirect and metadata.get("pid", 0)>0 and metadata.get("window-type", [None])[0]=="NORMAL" \
     1446            and metadata.get("transient-for", None) is None and sys.platform=="darwin":
     1447            #log.info("forcing utility window")
     1448            #metadata["window-type"] = ["UTILITY"]
     1449            pid = metadata["pid"]
     1450            for twid, twin in self._id_to_window.items():
     1451                if twin._metadata.get("pid")==pid and not twin._override_redirect:
     1452                    log.info("forcing transient for %s", twid)
     1453                    metadata["transient-for"] = twid
     1454                    #self.timeout_add(20, self.send_focus, wid)
     1455                    break
     1456
    14331457        window = None
    14341458        for cwc in client_window_classes:
    14351459            try:
     
    14431467        self._id_to_window[wid] = window
    14441468        self._window_to_id[window] = wid
    14451469        window.show()
     1470        #if override_redirect:
     1471        #    self.timeout_add(10, window.present)
     1472        #window.present()
     1473        log.info("make_new_window%s=%s, group_leader_window=%s", (wid, x, y, w, h, metadata, override_redirect, client_properties, auto_refresh_delay), window, self._window_to_id.get(group_leader_window))
     1474        if override_redirect:
     1475            self._or_focused = wid
     1476        else:
     1477            self._or_focused = None
    14461478        return window
    14471479
     1480    def send_mouse_position(self, packet):
     1481        log.info("send_mouse_position%s or_focused=%s", packet, self._or_focused)
     1482        if self._or_focused!=packet[1] and self._or_focused:
     1483            log.info("forcing OR for mouse position")
     1484            packet[1] = self._or_focused
     1485        #"button-action", self._id, button, pressed, pointer, modifiers, buttons])
     1486        XpraClientBase.send_mouse_position(self, packet)
     1487
     1488    def send_positional(self, packet):
     1489        if self._or_focused!=packet[1] and self._or_focused:
     1490            log.info("forcing OR for mouse position")
     1491            packet[1] = self._or_focused
     1492        if self._or_focused and packet[0]=="button-action" and packet[3] is False:
     1493            log.info("NOT swallowing button release")
     1494            #return
     1495        XpraClientBase.send_positional(self, packet)
     1496
    14481497    def get_group_leader(self, metadata, override_redirect):
    14491498        #subclasses that wish to implement the feature may override this method
    14501499        return None
     
    16261675            del self._id_to_window[wid]
    16271676            del self._window_to_id[window]
    16281677            self.destroy_window(wid, window)
     1678        if self._or_focused==wid:
     1679            self._or_focused = None
    16291680        if len(self._id_to_window)==0:
    16301681            log("last window gone, clearing key repeat")
    16311682            self.keyboard_helper.clear_repeat()