wlmaker
Loading...
Searching...
No Matches
Macros | Functions | Variables
surface.c File Reference
#include "surface.h"
#include "element.h"
#include "gfxbuf.h"
#include "util.h"
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_seat.h>
Include dependency graph for surface.c:

Functions

static bool _wlmtk_surface_init (wlmtk_surface_t *surface_ptr, struct wlr_surface *wlr_surface_ptr, wlmtk_env_t *env_ptr)
 
static void _wlmtk_surface_fini (wlmtk_surface_t *surface_ptr)
 
static void _wlmtk_surface_element_destroy (wlmtk_element_t *element_ptr)
 
static struct wlr_scene_node * _wlmtk_surface_element_create_scene_node (wlmtk_element_t *element_ptr, struct wlr_scene_tree *wlr_scene_tree_ptr)
 
static void _wlmtk_surface_element_get_dimensions (wlmtk_element_t *element_ptr, int *left_ptr, int *top_ptr, int *right_ptr, int *bottom_ptr)
 
static void _wlmtk_surface_element_get_pointer_area (wlmtk_element_t *element_ptr, int *left_ptr, int *top_ptr, int *right_ptr, int *bottom_ptr)
 
static void _wlmtk_surface_element_pointer_leave (wlmtk_element_t *element_ptr)
 
static bool _wlmtk_surface_element_pointer_motion (wlmtk_element_t *element_ptr, double x, double y, uint32_t time_msec)
 
static bool _wlmtk_surface_element_pointer_button (wlmtk_element_t *element_ptr, const wlmtk_button_event_t *button_event_ptr)
 
static bool _wlmtk_surface_element_pointer_axis (wlmtk_element_t *element_ptr, struct wlr_pointer_axis_event *wlr_pointer_axis_event_ptr)
 
static void _wlmtk_surface_handle_wlr_scene_tree_node_destroy (struct wl_listener *listener_ptr, void *data_ptr)
 
static void _wlmtk_surface_handle_surface_commit (struct wl_listener *listener_ptr, void *data_ptr)
 
static void _wlmtk_surface_commit_size (wlmtk_surface_t *surface_ptr, int width, int height)
 
wlmtk_surface_twlmtk_surface_create (struct wlr_surface *wlr_surface_ptr, wlmtk_env_t *env_ptr)
 
void wlmtk_surface_destroy (wlmtk_surface_t *surface_ptr)
 
wlmtk_element_twlmtk_surface_element (wlmtk_surface_t *surface_ptr)
 
void wlmtk_surface_get_size (wlmtk_surface_t *surface_ptr, int *width_ptr, int *height_ptr)
 
void wlmtk_surface_set_activated (wlmtk_surface_t *surface_ptr, bool activated)
 
void wlmtk_surface_connect_map_listener_signal (wlmtk_surface_t *surface_ptr, struct wl_listener *listener_ptr, wl_notify_func_t handler)
 
void wlmtk_surface_connect_unmap_listener_signal (wlmtk_surface_t *surface_ptr, struct wl_listener *listener_ptr, wl_notify_func_t handler)
 
static void _wlmtk_fake_surface_element_destroy (wlmtk_element_t *element_ptr)
 
static struct wlr_scene_node * _wlmtk_fake_surface_element_create_scene_node (wlmtk_element_t *element_ptr, struct wlr_scene_tree *wlr_scene_tree_ptr)
 
static bool _wlmtk_fake_surface_element_pointer_motion (wlmtk_element_t *element_ptr, double x, double y, uint32_t time_msec)
 
static bool _wlmtk_fake_surface_element_pointer_button (wlmtk_element_t *element_ptr, const wlmtk_button_event_t *button_event_ptr)
 
static void _wlmtk_fake_surface_element_pointer_leave (wlmtk_element_t *element_ptr)
 
wlmtk_fake_surface_twlmtk_fake_surface_create (void)
 
void wlmtk_fake_surface_commit_size (wlmtk_fake_surface_t *fake_surface_ptr, int width, int height)
 
void wlmtk_fake_surface_destroy (wlmtk_fake_surface_t *fake_surface_ptr)
 
static void test_create_destroy (bs_test_t *test_ptr)
 
static void test_fake_commit (bs_test_t *test_ptr)
 

Variables

static const wlmtk_element_vmt_t surface_element_vmt
 
static const wlmtk_element_vmt_t _wlmtk_fake_surface_element_vmt
 
const bs_test_case_t wlmtk_surface_test_cases []
 

Detailed Description

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function Documentation

◆ _wlmtk_fake_surface_element_create_scene_node()

struct wlr_scene_node * _wlmtk_fake_surface_element_create_scene_node ( wlmtk_element_t * element_ptr,
struct wlr_scene_tree * wlr_scene_tree_ptr )
static

Fake implementation of wlmtk_element_vmt_t::create_scene_node.

◆ _wlmtk_fake_surface_element_destroy()

void _wlmtk_fake_surface_element_destroy ( wlmtk_element_t * element_ptr)
static

Fake implementation of the dtor, wlmtk_element_vmt_t::destroy.

◆ _wlmtk_fake_surface_element_pointer_button()

bool _wlmtk_fake_surface_element_pointer_button ( wlmtk_element_t * element_ptr,
const wlmtk_button_event_t * button_event_ptr )
static

Fake for wlmtk_element_vmt_t::pointer_button. Returns true.

◆ _wlmtk_fake_surface_element_pointer_leave()

void _wlmtk_fake_surface_element_pointer_leave ( wlmtk_element_t * element_ptr)
static

Fake for wlmtk_element_vmt_t::pointer_leave. Does nothing.

◆ _wlmtk_fake_surface_element_pointer_motion()

bool _wlmtk_fake_surface_element_pointer_motion ( wlmtk_element_t * element_ptr,
double x,
double y,
uint32_t time_msec )
static

Fake for wlmtk_element_vmt_t::pointer_motion. True if in committed.

◆ _wlmtk_surface_commit_size()

void _wlmtk_surface_commit_size ( wlmtk_surface_t * surface_ptr,
int width,
int height )
static

Surface commits a new size: Store the size, and update the parent's layout.

Parameters
surface_ptr
width
height

◆ _wlmtk_surface_element_create_scene_node()

struct wlr_scene_node * _wlmtk_surface_element_create_scene_node ( wlmtk_element_t * element_ptr,
struct wlr_scene_tree * wlr_scene_tree_ptr )
static

Implements wlmtk_element_vmt_t::create_scene_node. Creates the node.

Parameters
element_ptr
wlr_scene_tree_ptr
Returns
The scene graph API node of the node displaying the surface and all of it's sub-surfaces. Or NULL on error.

◆ _wlmtk_surface_element_destroy()

void _wlmtk_surface_element_destroy ( wlmtk_element_t * element_ptr)
static

Implements wlmtk_element_vmt_t::destroy. Calls the dtor.

◆ _wlmtk_surface_element_get_dimensions()

void _wlmtk_surface_element_get_dimensions ( wlmtk_element_t * element_ptr,
int * left_ptr,
int * top_ptr,
int * right_ptr,
int * bottom_ptr )
static

Implementation of the element's get_dimensions method: Return dimensions.

Parameters
element_ptr
left_ptrLeftmost position. May be NULL.
top_ptrTopmost position. May be NULL.
right_ptrRightmost position. Ma be NULL.
bottom_ptrBottommost position. May be NULL.

◆ _wlmtk_surface_element_get_pointer_area()

void _wlmtk_surface_element_get_pointer_area ( wlmtk_element_t * element_ptr,
int * left_ptr,
int * top_ptr,
int * right_ptr,
int * bottom_ptr )
static

Overwrites the element's get_pointer_area method: Returns the extents of the surface and all subsurfaces.

Parameters
element_ptr
left_ptrLeftmost position. May be NULL.
top_ptrTopmost position. May be NULL.
right_ptrRightmost position. Ma be NULL.
bottom_ptrBottommost position. May be NULL.

◆ _wlmtk_surface_element_pointer_axis()

bool _wlmtk_surface_element_pointer_axis ( wlmtk_element_t * element_ptr,
struct wlr_pointer_axis_event * wlr_pointer_axis_event_ptr )
static

Passes pointer axis events further to the focused surface, if any.

The actual passing is handled by wlr_seat. Here we just verify that the currently-focused surface (or sub-surface) is part of this surface.

Parameters
element_ptr
wlr_pointer_axis_event_ptr
Returns
Whether the axis event was consumed.

◆ _wlmtk_surface_element_pointer_button()

bool _wlmtk_surface_element_pointer_button ( wlmtk_element_t * element_ptr,
const wlmtk_button_event_t * button_event_ptr )
static

Passes pointer button event further to the focused surface, if any.

The actual passing is handled by wlr_seat. Here we just verify that the currently-focused surface (or sub-surface) is part of this surface.

Parameters
element_ptr
button_event_ptr
Returns
Whether the button event was consumed.

◆ _wlmtk_surface_element_pointer_leave()

void _wlmtk_surface_element_pointer_leave ( wlmtk_element_t * element_ptr)
static

Implements the element's leave method: If there's a WLR (sub)surface currently holding focus, that will be cleared.

Parameters
element_ptr

◆ _wlmtk_surface_element_pointer_motion()

bool _wlmtk_surface_element_pointer_motion ( wlmtk_element_t * element_ptr,
double x,
double y,
uint32_t time_msec )
static

Pass pointer motion events to client's surface.

Identifies the surface (or sub-surface) at the given coordinates, and pass on the motion event to that surface. If needed, will update the seat's pointer focus.

Parameters
element_ptr
xPointer horizontal position, relative to this element's node.
yPointer vertical position, relative to this element's node.
time_msec
Returns
Whether if the motion is within the area.

◆ _wlmtk_surface_fini()

void _wlmtk_surface_fini ( wlmtk_surface_t * surface_ptr)
static

Un-initializes the surface.

Parameters
surface_ptr

◆ _wlmtk_surface_handle_surface_commit()

void _wlmtk_surface_handle_surface_commit ( struct wl_listener * listener_ptr,
void * data_ptr )
static

Handler for the commit signal of wlr_surface.

◆ _wlmtk_surface_handle_wlr_scene_tree_node_destroy()

void _wlmtk_surface_handle_wlr_scene_tree_node_destroy ( struct wl_listener * listener_ptr,
void * data_ptr )
static

Handler for the destroy signal of wlr_scene_tree_ptr->node.

We have this registered to clear out the extra pointer we're holding to wlmtk_surface_t::wlr_scene_tree_ptr. wlmtk_element_t has a separate destroy handler that will take care of actual cleanup.

◆ _wlmtk_surface_init()

bool _wlmtk_surface_init ( wlmtk_surface_t * surface_ptr,
struct wlr_surface * wlr_surface_ptr,
wlmtk_env_t * env_ptr )
static

Initializes the surface.

Parameters
surface_ptr
wlr_surface_ptr
env_ptr
Returns
true on success.

◆ test_create_destroy()

void test_create_destroy ( bs_test_t * test_ptr)
static

Tests ctor and dtor.

◆ test_fake_commit()

void test_fake_commit ( bs_test_t * test_ptr)
static

Exercises the request_size / commit flow.

◆ wlmtk_fake_surface_commit_size()

void wlmtk_fake_surface_commit_size ( wlmtk_fake_surface_t * fake_surface_ptr,
int width,
int height )

Fakes a wlr_surface commit event.

◆ wlmtk_fake_surface_create()

wlmtk_fake_surface_t * wlmtk_fake_surface_create ( void )

Ctor for the fake surface.

◆ wlmtk_fake_surface_destroy()

void wlmtk_fake_surface_destroy ( wlmtk_fake_surface_t * fake_surface_ptr)

Dtor for the fake surface.

◆ wlmtk_surface_connect_map_listener_signal()

void wlmtk_surface_connect_map_listener_signal ( wlmtk_surface_t * surface_ptr,
struct wl_listener * listener_ptr,
wl_notify_func_t handler )

Connects a listener and handler to the map signal of wlr_surface.

◆ wlmtk_surface_connect_unmap_listener_signal()

void wlmtk_surface_connect_unmap_listener_signal ( wlmtk_surface_t * surface_ptr,
struct wl_listener * listener_ptr,
wl_notify_func_t handler )

Connects a listener and handler to the unmap signal of wlr_surface.

◆ wlmtk_surface_create()

wlmtk_surface_t * wlmtk_surface_create ( struct wlr_surface * wlr_surface_ptr,
wlmtk_env_t * env_ptr )

Creates a toolkit surface from the wlr_surface_ptr.

Parameters
wlr_surface_ptr
env_ptr
Returns
A pointer to the wlmtk_surface_t. Must be destroyed by calling wlmtk_surface_destroy.

◆ wlmtk_surface_destroy()

void wlmtk_surface_destroy ( wlmtk_surface_t * surface_ptr)

Destroys the toolkit surface.

Parameters
surface_ptr

◆ wlmtk_surface_element()

wlmtk_element_t * wlmtk_surface_element ( wlmtk_surface_t * surface_ptr)

Returns a pointer to the surface's element superclass instance.

Parameters
surface_ptr
Returns
Pointer to the corresponding wlmtk_element_t.

◆ wlmtk_surface_get_size()

void wlmtk_surface_get_size ( wlmtk_surface_t * surface_ptr,
int * width_ptr,
int * height_ptr )

Returns committed size of the surface.

Parameters
surface_ptr
width_ptr
height_ptr

◆ wlmtk_surface_set_activated()

void wlmtk_surface_set_activated ( wlmtk_surface_t * surface_ptr,
bool activated )

Activates the surface.

Parameters
surface_ptr
activated

Variable Documentation

◆ _wlmtk_fake_surface_element_vmt

const wlmtk_element_vmt_t _wlmtk_fake_surface_element_vmt
static
Initial value:
= {
}
static bool _wlmtk_fake_surface_element_pointer_button(wlmtk_element_t *element_ptr, const wlmtk_button_event_t *button_event_ptr)
Definition surface.c:683
static struct wlr_scene_node * _wlmtk_fake_surface_element_create_scene_node(wlmtk_element_t *element_ptr, struct wlr_scene_tree *wlr_scene_tree_ptr)
Definition surface.c:649
static void _wlmtk_fake_surface_element_destroy(wlmtk_element_t *element_ptr)
Definition surface.c:639
static bool _wlmtk_fake_surface_element_pointer_motion(wlmtk_element_t *element_ptr, double x, double y, uint32_t time_msec)
Definition surface.c:669
static void _wlmtk_fake_surface_element_pointer_leave(wlmtk_element_t *element_ptr)
Definition surface.c:692

Extensions to the surface's super elements virtual methods.

◆ surface_element_vmt

const wlmtk_element_vmt_t surface_element_vmt
static
Initial value:
= {
}
static void _wlmtk_surface_element_get_pointer_area(wlmtk_element_t *element_ptr, int *left_ptr, int *top_ptr, int *right_ptr, int *bottom_ptr)
Definition surface.c:319
static bool _wlmtk_surface_element_pointer_axis(wlmtk_element_t *element_ptr, struct wlr_pointer_axis_event *wlr_pointer_axis_event_ptr)
Definition surface.c:499
static bool _wlmtk_surface_element_pointer_button(wlmtk_element_t *element_ptr, const wlmtk_button_event_t *button_event_ptr)
Definition surface.c:451
static bool _wlmtk_surface_element_pointer_motion(wlmtk_element_t *element_ptr, double x, double y, uint32_t time_msec)
Definition surface.c:386
static void _wlmtk_surface_element_destroy(wlmtk_element_t *element_ptr)
Definition surface.c:246
static void _wlmtk_surface_element_pointer_leave(wlmtk_element_t *element_ptr)
Definition surface.c:352
static struct wlr_scene_node * _wlmtk_surface_element_create_scene_node(wlmtk_element_t *element_ptr, struct wlr_scene_tree *wlr_scene_tree_ptr)
Definition surface.c:263
static void _wlmtk_surface_element_get_dimensions(wlmtk_element_t *element_ptr, int *left_ptr, int *top_ptr, int *right_ptr, int *bottom_ptr)
Definition surface.c:292

Method table for the element's virtual methods.

◆ wlmtk_surface_test_cases

const bs_test_case_t wlmtk_surface_test_cases[]
Initial value:
= {
{ 1, "create_destroy", test_create_destroy },
{ 1, "fake_commit", test_fake_commit },
{ 0, NULL, NULL }
}
static void test_create_destroy(bs_test_t *test_ptr)
Definition surface.c:711
static void test_fake_commit(bs_test_t *test_ptr)
Definition surface.c:726

Unit test cases.