Skip to content

Commit

Permalink
cosmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Nov 28, 2023
1 parent 826167d commit 41f435a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
27 changes: 14 additions & 13 deletions xpra/platform/posix/menu_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,32 +175,33 @@ def load_entry_icon(props : dict):
return props


def find_icon(*names):
def find_icon(*names) -> str:
if not EXPORT_ICONS:
return None
return ""
return find_resources_icon(*names) or \
find_pixmap_icon(*names) or \
find_theme_icon(*names) or \
find_glob_icon("apps", *names)


def find_resources_icon(*names):
def find_resources_icon(*names) -> str:
if not LOAD_FROM_RESOURCES:
return None
return ""
# loads the icon from our own list of icons:
for name in names:
fn = get_icon_filename(name)
if fn and os.path.exists(fn):
return fn
return None
return ""


def find_pixmap_icon(*names):
def find_pixmap_icon(*names) -> str:
if not LOAD_FROM_PIXMAPS:
return None
return ""
pixmaps_dirs = [d + '/icons' for d in os.environ.get("XDG_DATA_DIRS", "").split(":") if d]
pixmaps_dir = f"{sys.prefix}/share/pixmaps"
pixmaps_dirs += (pixmaps_dir, os.path.join(pixmaps_dir, "comps"))
icons_dir = f"{sys.prefix}/share/icons"
pixmaps_dirs += (pixmaps_dir, os.path.join(pixmaps_dir, "comps"), icons_dir)
for d in pixmaps_dirs:
if not os.path.exists(d) or not os.path.isdir(d):
continue
Expand All @@ -209,21 +210,21 @@ def find_pixmap_icon(*names):
fn = os.path.join(d, f"{name}.{ext}")
if fn and os.path.exists(fn):
return fn
return None
return ""


def find_theme_icon(*names):
def find_theme_icon(*names) -> str:
if not LOAD_FROM_THEME:
return None
return ""
if not (IconTheme and Config and themes):
return None
return ""
size = Config.icon_size
for name in names:
for theme in themes.values():
fn = IconTheme.LookupIcon(name, size, theme=theme, extensions=EXTENSIONS)
if fn and os.path.exists(fn):
return fn
return None
return ""


def find_glob_icon(*names, category: str = "categories"):
Expand Down
26 changes: 13 additions & 13 deletions xpra/server/source/networkstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ class NetworkStateMixin(StubSourceMixin):
def is_needed(cls, caps : typedict) -> bool:
return (
caps.boolget("network-state") or
typedict(caps.dictget("network") or {}).intget("pings")>0 or
caps.boolget("ping-echo-sourceid") #legacy clients
typedict(caps.dictget("network") or {}).intget("pings") > 0 or
caps.boolget("ping-echo-sourceid") # legacy clients
)

def init_state(self) -> None:
self.last_ping_echoed_time = 0
self.check_ping_echo_timers : dict[int,int] = {}
self.check_ping_echo_timers : dict[int, int] = {}
self.ping_timer = 0
self.bandwidth_limit = 0
self.client_load = (0,0,0)
self.client_connection_data : dict[str,Any] = {}
self.client_connection_data : dict[str, Any] = {}

def cleanup(self) -> None:
self.cancel_ping_echo_timers()
self.cancel_ping_timer()

def get_caps(self) -> dict[str,Any]:
def get_caps(self) -> dict[str, Any]:
return {"ping-echo-sourceid" : True}

def get_info(self) -> dict[str,Any]:
def get_info(self) -> dict[str, Any]:
lpe = 0
if self.last_ping_echoed_time>0:
if self.last_ping_echoed_time > 0:
lpe = int(monotonic()*1000-self.last_ping_echoed_time)
info = {
"bandwidth-limit" : {
Expand All @@ -62,7 +62,7 @@ def get_info(self) -> dict[str,Any]:
# pings:
def ping(self) -> None:
self.ping_timer = 0
#NOTE: all ping time/echo time/load avg values are in milliseconds
# NOTE: all ping time/echo time/load avg values are in milliseconds
now_ms = int(1000*monotonic())
log("sending ping to %s with time=%s", self.protocol, now_ms)
self.send_async("ping", now_ms, int(time.time()*1000), will_have_more=False)
Expand All @@ -82,20 +82,20 @@ def cancel_ping_echo_timers(self) -> None:
self.source_remove(t)

def process_ping(self, time_to_echo, sid) -> None:
l1,l2,l3 = 0,0,0
l1, l2, l3 = 0, 0, 0
cl = -1
if PING_DETAILS:
#send back the load average:
# send back the load average:
if POSIX:
fl1, fl2, fl3 = os.getloadavg()
l1,l2,l3 = int(fl1*1000), int(fl2*1000), int(fl3*1000)
#and the last client ping latency we measured (if any):
l1, l2, l3 = int(fl1*1000), int(fl2*1000), int(fl3*1000)
# and the last client ping latency we measured (if any):
stats = getattr(self, "statistics", None)
if stats and stats.client_ping_latency:
_, cl = stats.client_ping_latency[-1]
cl = int(1000.0*cl)
self.send_async("ping_echo", time_to_echo, l1, l2, l3, cl, sid, will_have_more=False)
#if the client is pinging us, ping it too:
# if the client is pinging us, ping it too:
if not self.ping_timer:
self.ping_timer = self.timeout_add(500, self.ping)

Expand Down

0 comments on commit 41f435a

Please sign in to comment.