def __init__(self, parent: Union[WindowType, XdgPopupWindow], xdg_popup: XdgPopup): self.parent = parent self.xdg_popup = xdg_popup self.core: Core = parent.core self.popups: List[XdgPopupWindow] = [] # Keep on output if isinstance(parent, XdgPopupWindow): # This is a nested XdgPopup self.output: Output = parent.output self.output_box: Box = parent.output_box else: # Parent is an XdgSurface; This is a first-level XdgPopup box = xdg_popup.base.get_geometry() lx, ly = self.core.output_layout.closest_point( parent.x + box.x, parent.y + box.y) wlr_output = self.core.output_layout.output_at(lx, ly) self.output = wlr_output.data box = Box(*self.output.get_geometry()) box.x = round(box.x - lx) box.y = round(box.y - ly) self.output_box = box xdg_popup.unconstrain_from_box(self.output_box) self.add_listener(xdg_popup.base.map_event, self._on_map) self.add_listener(xdg_popup.base.unmap_event, self._on_unmap) self.add_listener(xdg_popup.base.destroy_event, self._on_destroy) self.add_listener(xdg_popup.base.new_popup_event, self._on_new_popup) self.add_listener(xdg_popup.base.surface.commit_event, self._on_commit)
def _render_surface(self, surface: Surface, sx: int, sy: int, rdata: Tuple) -> None: texture = surface.get_texture() if texture is None: return now, window, wx, wy, opacity, scale = rdata x = (wx + sx) * scale y = (wy + sy) * scale width = surface.current.width * scale height = surface.current.height * scale transform_matrix = self.transform_matrix if window.borderwidth: bw = int(window.borderwidth * scale) if surface == window.surface.surface: outer_w = width + bw * 2 outer_h = height + bw * 2 num = len(window.bordercolor) bws = [bw // num] * num for i in range(bw % num): bws[i] += 1 coord = 0 for i, bc in enumerate(window.bordercolor): border = Box( int(x + coord), int(y + coord), int(outer_w - coord * 2), int(bws[i]), ) self.renderer.render_rect(border, bc, transform_matrix) # Top border border.y = int(y + outer_h - bws[i] - coord) self.renderer.render_rect( border, bc, transform_matrix) # Bottom border border.y = int(y + coord) border.width = int(bws[i]) border.height = int(outer_h - coord * 2) self.renderer.render_rect(border, bc, transform_matrix) # Left border border.x = int(x + outer_w - bws[i] - coord) self.renderer.render_rect(border, bc, transform_matrix) # Right border coord += bws[i] x += bw y += bw box = Box( int(x), int(y), int(width), int(height), ) inverse = wlrOutput.transform_invert(surface.current.transform) matrix = Matrix.project_box(box, inverse, 0, transform_matrix) self.renderer.render_texture_with_matrix(texture, matrix, opacity) surface.send_frame_done(now)
def _render_surface( self, surface: Surface, sx: int, sy: int, data: Tuple[Output, View, Timespec] ) -> None: output, view, now = data texture = surface.get_texture() if texture is None: return ox, oy = self._output_layout.output_coords(output) ox += view.x + sx oy += view.y + sy box = Box( int(ox * output.scale), int(oy * output.scale), int(surface.current.width * output.scale), int(surface.current.height * output.scale), ) transform = surface.current.transform inverse = Output.transform_invert(transform) matrix = Matrix.project_box(box, inverse, 0, output.transform_matrix) self._renderer.render_texture_with_matrix(texture, matrix, 1) surface.send_frame_done(now)
def _begin_interactive(self, cursor_mode: CursorMode, edges: Edges) -> None: """This function sets up an interactive move or resize operation""" focused_surface = self.tinywl_server._seat.pointer_state.focused_surface if self.xdg_surface.surface != focused_surface: # Deny move/resize requests from unfocused clients logging.info("Denied begin interactive") # TODO: this doesn't seem to be correct for alacritty, should return here self.tinywl_server.grabbed_view = self self.tinywl_server.cursor_mode = cursor_mode if cursor_mode == CursorMode.MOVE: self.tinywl_server.grab_x = self.tinywl_server._cursor.x - self.x self.tinywl_server.grab_y = self.tinywl_server._cursor.y - self.y elif cursor_mode == CursorMode.RESIZE: box = self.xdg_surface.get_geometry() border_x = self.x + box.x + (box.width if edges & Edges.RIGHT else 0) border_y = self.y + box.y + (box.height if edges & Edges.BOTTOM else 0) self.tinywl_server.grab_x = self.tinywl_server._cursor.x - border_x self.tinywl_server.grab_y = self.tinywl_server._cursor.y - border_y self.tinywl_server.grab_geobox = Box(box.x + int(self.x), box.y + int(self.y), box.width, box.height) self.tinywl_server.resize_edges = edges
def _render_surface(self, surface: Surface, sx: int, sy: int, rdata: Tuple) -> None: texture = surface.get_texture() if texture is None: return now, window, wx, wy, opacity, scale = rdata x = (wx + sx) * scale y = (wy + sy) * scale width = surface.current.width * scale height = surface.current.height * scale transform_matrix = self.transform_matrix if window.borderwidth: bw = window.borderwidth * scale if surface == window.surface.surface: bc = window.bordercolor border = Box( int(x), int(y), int(width + bw * 2), int(bw), ) x += bw y += bw self.renderer.render_rect(border, bc, transform_matrix) # Top border border.y = int(y + height) self.renderer.render_rect(border, bc, transform_matrix) # Bottom border border.y = int(y - bw) border.width = int(bw) border.height = int(height + bw * 2) self.renderer.render_rect(border, bc, transform_matrix) # Left border border.x = int(x + width) self.renderer.render_rect(border, bc, transform_matrix) # Right border else: x += bw y += bw box = Box( int(x), int(y), int(width), int(height), ) inverse = wlrOutput.transform_invert(surface.current.transform) matrix = Matrix.project_box(box, inverse, 0, transform_matrix) self.renderer.render_texture_with_matrix(texture, matrix, opacity) surface.send_frame_done(now)