Skip to content

Commit

Permalink
[proxy] do not call destructor on not yet attached proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
aslpavel committed Sep 29, 2024
1 parent 15d6602 commit a26b564
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion wayland/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(self, debug: bool | None = None, is_server: bool = False) -> None:

self._id_last: Id = Id(0)
self._id_free: list[Id] = []
self._proxies: dict[Id, Proxy] = {}
self._proxies: dict[Id, Proxy] = {} # all known proxies

def create_proxy(self, proxy_type: type[P]) -> P:
"""Create proxy by proxy type"""
Expand Down
4 changes: 2 additions & 2 deletions wayland/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def _generate_request(
# no-op for disconnected destructor
# fmt: off
print(
" if self._is_destroyed or self._is_detached or self._connection.is_terminated:\n"
" if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:\n"
" return None\n"
" self._is_destroyed = True",
file=module,
Expand All @@ -235,7 +235,7 @@ def _generate_request(
result_vals.append(result_desc.name)

# submit
values = "tuple()"
values = "()"
if request.args:
values = "({},)".format(", ".join(arg.name for arg in request.args))
print(
Expand Down
70 changes: 35 additions & 35 deletions wayland/protocol/wayland.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ def create_buffer(self, offset: int, width: int, height: int, stride: int, forma

def destroy(self) -> None:
"""destroy the pool"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(1), tuple())
self._call(OpCode(1), ())
return None

def resize(self, size: int) -> None:
Expand Down Expand Up @@ -420,10 +420,10 @@ def create_pool(self, fd: Fd, size: int) -> WlShmPool:

def release(self) -> None:
"""release the shm object"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(1), tuple())
self._call(OpCode(1), ())
return None

def __enter__(self) -> WlShm:
Expand Down Expand Up @@ -601,10 +601,10 @@ def __init__(self, id: Id, connection: Connection) -> None:

def destroy(self) -> None:
"""destroy a buffer"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(0), tuple())
self._call(OpCode(0), ())
return None

def __enter__(self) -> WlBuffer:
Expand Down Expand Up @@ -669,15 +669,15 @@ def receive(self, mime_type: str, fd: Fd) -> None:

def destroy(self) -> None:
"""destroy data offer"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(2), tuple())
self._call(OpCode(2), ())
return None

def finish(self) -> None:
"""the offer will no longer be used"""
self._call(OpCode(3), tuple())
self._call(OpCode(3), ())
return None

def set_actions(self, dnd_actions: WlDataDeviceManager.DndAction, preferred_action: WlDataDeviceManager.DndAction) -> None:
Expand Down Expand Up @@ -765,10 +765,10 @@ def offer(self, mime_type: str) -> None:

def destroy(self) -> None:
"""destroy the data source"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(1), tuple())
self._call(OpCode(1), ())
return None

def set_actions(self, dnd_actions: WlDataDeviceManager.DndAction) -> None:
Expand Down Expand Up @@ -877,10 +877,10 @@ def set_selection(self, source: WlDataSource | None, serial: int) -> None:

def release(self) -> None:
"""destroy data device"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(2), tuple())
self._call(OpCode(2), ())
return None

def __enter__(self) -> WlDataDevice:
Expand Down Expand Up @@ -1111,7 +1111,7 @@ def resize(self, seat: WlSeat, serial: int, edges: Resize) -> None:

def set_toplevel(self) -> None:
"""make the surface a toplevel surface"""
self._call(OpCode(3), tuple())
self._call(OpCode(3), ())
return None

def set_transient(self, parent: WlSurface, x: int, y: int, flags: Transient) -> None:
Expand Down Expand Up @@ -1237,10 +1237,10 @@ def __init__(self, id: Id, connection: Connection) -> None:

def destroy(self) -> None:
"""delete surface"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(0), tuple())
self._call(OpCode(0), ())
return None

def attach(self, buffer: WlBuffer | None, x: int, y: int) -> None:
Expand Down Expand Up @@ -1271,7 +1271,7 @@ def set_input_region(self, region: WlRegion | None) -> None:

def commit(self) -> None:
"""commit pending surface state"""
self._call(OpCode(6), tuple())
self._call(OpCode(6), ())
return None

def set_buffer_transform(self, transform: WlOutput.Transform) -> None:
Expand Down Expand Up @@ -1399,10 +1399,10 @@ def get_touch(self) -> WlTouch:

def release(self) -> None:
"""release the seat object"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(3), tuple())
self._call(OpCode(3), ())
return None

def __enter__(self) -> WlSeat:
Expand Down Expand Up @@ -1516,10 +1516,10 @@ def set_cursor(self, serial: int, surface: WlSurface | None, hotspot_x: int, hot

def release(self) -> None:
"""release the pointer object"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(1), tuple())
self._call(OpCode(1), ())
return None

def __enter__(self) -> WlPointer:
Expand Down Expand Up @@ -1673,10 +1673,10 @@ def __init__(self, id: Id, connection: Connection) -> None:

def release(self) -> None:
"""release the keyboard object"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(0), tuple())
self._call(OpCode(0), ())
return None

def __enter__(self) -> WlKeyboard:
Expand Down Expand Up @@ -1768,10 +1768,10 @@ def __init__(self, id: Id, connection: Connection) -> None:

def release(self) -> None:
"""release the touch object"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(0), tuple())
self._call(OpCode(0), ())
return None

def __enter__(self) -> WlTouch:
Expand Down Expand Up @@ -1884,10 +1884,10 @@ def __init__(self, id: Id, connection: Connection) -> None:

def release(self) -> None:
"""release the output object"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(0), tuple())
self._call(OpCode(0), ())
return None

def __enter__(self) -> WlOutput:
Expand Down Expand Up @@ -1990,10 +1990,10 @@ def __init__(self, id: Id, connection: Connection) -> None:

def destroy(self) -> None:
"""destroy region"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(0), tuple())
self._call(OpCode(0), ())
return None

def add(self, x: int, y: int, width: int, height: int) -> None:
Expand Down Expand Up @@ -2044,10 +2044,10 @@ def __init__(self, id: Id, connection: Connection) -> None:

def destroy(self) -> None:
"""unbind from the subcompositor interface"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(0), tuple())
self._call(OpCode(0), ())
return None

def get_subsurface(self, surface: WlSurface, parent: WlSurface) -> WlSubsurface:
Expand Down Expand Up @@ -2107,10 +2107,10 @@ def __init__(self, id: Id, connection: Connection) -> None:

def destroy(self) -> None:
"""remove sub-surface interface"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(0), tuple())
self._call(OpCode(0), ())
return None

def set_position(self, x: int, y: int) -> None:
Expand All @@ -2130,12 +2130,12 @@ def place_below(self, sibling: WlSurface) -> None:

def set_sync(self) -> None:
"""set sub-surface to synchronized mode"""
self._call(OpCode(4), tuple())
self._call(OpCode(4), ())
return None

def set_desync(self) -> None:
"""set sub-surface to desynchronized mode"""
self._call(OpCode(5), tuple())
self._call(OpCode(5), ())
return None

def __enter__(self) -> WlSubsurface:
Expand Down
10 changes: 5 additions & 5 deletions wayland/protocol/wlr_layer_shell_unstable_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from typing import Any, ClassVar
from collections.abc import Callable
from ..base import *
from .xdg_shell import *
from .wayland import *
from .xdg_shell import *

__all__ = [
"ZwlrLayerShellV1",
Expand Down Expand Up @@ -58,10 +58,10 @@ def get_layer_surface(self, surface: WlSurface, output: WlOutput | None, layer:

def destroy(self) -> None:
"""destroy the layer_shell object"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(1), tuple())
self._call(OpCode(1), ())
return None

def __enter__(self) -> ZwlrLayerShellV1:
Expand Down Expand Up @@ -187,10 +187,10 @@ def ack_configure(self, serial: int) -> None:

def destroy(self) -> None:
"""destroy the layer_surface"""
if self._is_destroyed or self._is_detached or self._connection.is_terminated:
if self._is_destroyed or not self._is_attached or self._is_detached or self._connection.is_terminated:
return None
self._is_destroyed = True
self._call(OpCode(7), tuple())
self._call(OpCode(7), ())
return None

def set_layer(self, layer: ZwlrLayerShellV1.Layer) -> None:
Expand Down
Loading

0 comments on commit a26b564

Please sign in to comment.