wlmaker
Loading...
Searching...
No Matches
Classes | Macros | Functions | Variables
container.c File Reference
#include "container.h"
#include "util.h"
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_scene.h>
Include dependency graph for container.c:

Classes

struct  fake_parent_container_t
 

Functions

static void _wlmtk_container_element_dlnode_destroy (bs_dllist_node_t *dlnode_ptr, void *ud_ptr)
 
static struct wlr_scene_node * _wlmtk_container_element_create_scene_node (wlmtk_element_t *element_ptr, struct wlr_scene_tree *wlr_scene_tree_ptr)
 
static void _wlmtk_container_element_get_dimensions (wlmtk_element_t *element_ptr, int *left_ptr, int *top_ptr, int *right_ptr, int *bottom_ptr)
 
static void _wlmtk_container_element_get_pointer_area (wlmtk_element_t *element_ptr, int *left_ptr, int *top_ptr, int *right_ptr, int *bottom_ptr)
 
static bool _wlmtk_container_element_pointer_motion (wlmtk_element_t *element_ptr, double x, double y, uint32_t time_msec)
 
static bool _wlmtk_container_element_pointer_button (wlmtk_element_t *element_ptr, const wlmtk_button_event_t *button_event_ptr)
 
static bool _wlmtk_container_element_pointer_axis (wlmtk_element_t *element_ptr, struct wlr_pointer_axis_event *wlr_pointer_axis_event_ptr)
 
static void _wlmtk_container_element_pointer_enter (wlmtk_element_t *element_ptr)
 
static void _wlmtk_container_element_keyboard_blur (wlmtk_element_t *element_ptr)
 
static bool _wlmtk_container_element_keyboard_event (wlmtk_element_t *element_ptr, struct wlr_keyboard_key_event *wlr_keyboard_key_event_ptr, const xkb_keysym_t *key_syms, size_t key_syms_count, uint32_t modifiers)
 
static void handle_wlr_scene_tree_node_destroy (struct wl_listener *listener_ptr, void *data_ptr)
 
static bool update_pointer_focus_at (wlmtk_container_t *container_ptr, double x, double y, uint32_t time_msec)
 
static void _wlmtk_container_update_layout (wlmtk_container_t *container_ptr)
 
bool wlmtk_container_init (wlmtk_container_t *container_ptr, wlmtk_env_t *env_ptr)
 
bool wlmtk_container_init_attached (wlmtk_container_t *container_ptr, wlmtk_env_t *env_ptr, struct wlr_scene_tree *root_wlr_scene_tree_ptr)
 
wlmtk_container_vmt_t wlmtk_container_extend (wlmtk_container_t *container_ptr, const wlmtk_container_vmt_t *container_vmt_ptr)
 
void wlmtk_container_fini (wlmtk_container_t *container_ptr)
 
void wlmtk_container_add_element (wlmtk_container_t *container_ptr, wlmtk_element_t *element_ptr)
 
void wlmtk_container_add_element_atop (wlmtk_container_t *container_ptr, wlmtk_element_t *reference_element_ptr, wlmtk_element_t *element_ptr)
 
void wlmtk_container_remove_element (wlmtk_container_t *container_ptr, wlmtk_element_t *element_ptr)
 
void wlmtk_container_raise_element_to_top (wlmtk_container_t *container_ptr, wlmtk_element_t *element_ptr)
 
void wlmtk_container_update_pointer_focus (wlmtk_container_t *container_ptr)
 
void wlmtk_container_set_keyboard_focus_element (wlmtk_container_t *container_ptr, wlmtk_element_t *element_ptr)
 
struct wlr_scene_tree * wlmtk_container_wlr_scene_tree (wlmtk_container_t *container_ptr)
 
wlmtk_container_twlmtk_container_create_fake_parent (void)
 
void wlmtk_container_destroy_fake_parent (wlmtk_container_t *container_ptr)
 
static void test_init_fini (bs_test_t *test_ptr)
 
static void test_add_remove (bs_test_t *test_ptr)
 
static void test_add_remove_with_scene_graph (bs_test_t *test_ptr)
 
static void test_add_with_raise (bs_test_t *test_ptr)
 
static void test_pointer_motion (bs_test_t *test_ptr)
 
static void test_pointer_focus (bs_test_t *test_ptr)
 
static void test_pointer_focus_move (bs_test_t *test_ptr)
 
static void test_pointer_focus_layered (bs_test_t *test_ptr)
 
static void test_pointer_button (bs_test_t *test_ptr)
 
static void test_pointer_axis (bs_test_t *test_ptr)
 
static void test_keyboard_event (bs_test_t *test_ptr)
 
static void test_keyboard_focus (bs_test_t *test_ptr)
 

Variables

static const wlmtk_element_vmt_t container_element_vmt
 
static const wlmtk_container_vmt_t container_vmt
 
const bs_test_case_t wlmtk_container_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_container_element_create_scene_node()

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

Implementation of the superclass wlmtk_element_t::create_scene_node method.

Creates the wlroots scene graph tree for the container, and will attach all already-contained elements to the scene graph, as well.

Parameters
element_ptr
wlr_scene_tree_ptr
Returns
Pointer to the scene graph API node.

◆ _wlmtk_container_element_dlnode_destroy()

void _wlmtk_container_element_dlnode_destroy ( bs_dllist_node_t * dlnode_ptr,
void * ud_ptr )
static

Calls dtor for wlmtk_element_t at dlnode_ptr in ud_ptr.

◆ _wlmtk_container_element_get_dimensions()

void _wlmtk_container_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_container_element_get_pointer_area()

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

Returns the minimal rectangle covering all element's pointer areas.

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_container_element_keyboard_blur()

void _wlmtk_container_element_keyboard_blur ( wlmtk_element_t * element_ptr)
static

Implements wlmtk_element_vmt_t::keyboard_blur. Blurs all children.

◆ _wlmtk_container_element_keyboard_event()

bool _wlmtk_container_element_keyboard_event ( wlmtk_element_t * element_ptr,
struct wlr_keyboard_key_event * wlr_keyboard_key_event_ptr,
const xkb_keysym_t * key_syms,
size_t key_syms_count,
uint32_t modifiers )
static

Handler for keyboard events: Pass to keyboard-focussed element, if any.

◆ _wlmtk_container_element_pointer_axis()

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

Implementation of the element's axis method: Handles axis events, by forwarding it to the element having pointer focus.

Parameters
element_ptr
wlr_pointer_axis_event_ptr
Returns
true if the axis event was handled.

◆ _wlmtk_container_element_pointer_button()

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

Implementation of the element's pointer_button() method. Forwards it to the element currently having pointer focus.

Parameters
element_ptr
button_event_ptr
Returns
true if the button was handled.

◆ _wlmtk_container_element_pointer_enter()

void _wlmtk_container_element_pointer_enter ( wlmtk_element_t * element_ptr)
static

Handler for when the pointer enters the area. Nothing for container.

◆ _wlmtk_container_element_pointer_motion()

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

Implementation of the element's motion method: Handle pointer moves.

Parameters
element_ptr
x
y
time_msec
Returns
Whether this container has an element that accepts the emotion.

◆ _wlmtk_container_update_layout()

void _wlmtk_container_update_layout ( wlmtk_container_t * container_ptr)
static

Base implementation of wlmtk_container_vmt_t::update_layout. If there's a parent, will call wlmtk_container_update_layout. Otherwise, will update the pointer focus.

Parameters
container_ptr

◆ handle_wlr_scene_tree_node_destroy()

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

Handles the 'destroy' callback of wlr_scene_tree_ptr->node.

Will also detach (but not destroy) each of the still-contained elements.

Parameters
listener_ptr
data_ptr

◆ test_add_remove()

void test_add_remove ( bs_test_t * test_ptr)
static

Exercises adding and removing elements, verifies destruction on fini.

◆ test_add_remove_with_scene_graph()

void test_add_remove_with_scene_graph ( bs_test_t * test_ptr)
static

Tests that elements are attached, resp. detached from scene graph.

◆ test_add_with_raise()

void test_add_with_raise ( bs_test_t * test_ptr)
static

Tests that elements inserted at position are also placed in scene graph.

◆ test_init_fini()

void test_init_fini ( bs_test_t * test_ptr)
static

Exercises init() and fini() methods, verifies dtor forwarding.

◆ test_keyboard_event()

void test_keyboard_event ( bs_test_t * test_ptr)
static

Tests that keyboard event are forwarded to element with keyboard focus.

◆ test_keyboard_focus()

void test_keyboard_focus ( bs_test_t * test_ptr)
static

Test that keyboard focus is propagated and respects element removal.

◆ test_pointer_axis()

void test_pointer_axis ( bs_test_t * test_ptr)
static

Tests that axis events are forwarded to element with pointer focus.

◆ test_pointer_button()

void test_pointer_button ( bs_test_t * test_ptr)
static

Tests that pointer DOWN is forwarded to element with pointer focus.

◆ test_pointer_focus()

void test_pointer_focus ( bs_test_t * test_ptr)
static

Tests that pointer focus is updated when elements are updated.

◆ test_pointer_focus_layered()

void test_pointer_focus_layered ( bs_test_t * test_ptr)
static

Tests that pointer focus is updated across layers of containers.

◆ test_pointer_focus_move()

void test_pointer_focus_move ( bs_test_t * test_ptr)
static

Tests that pointer focus is updated when elements are moved.

◆ test_pointer_motion()

void test_pointer_motion ( bs_test_t * test_ptr)
static

Tests the 'motion' method for container.

◆ update_pointer_focus_at()

bool update_pointer_focus_at ( wlmtk_container_t * container_ptr,
double x,
double y,
uint32_t time_msec )
static

Updates pointer focus of container for position (x, y).

Updates wlmtk_container_t::pointer_focus_element_ptr.

Parameters
container_ptr
x
y
time_msec
Returns
Whether there was an element acception the motion at (x, y).

◆ wlmtk_container_add_element()

void wlmtk_container_add_element ( wlmtk_container_t * container_ptr,
wlmtk_element_t * element_ptr )

Adds element_ptr to the container.

Requires that element_ptr is not added to a container yet. The element will be added at the top of the container.

Parameters
container_ptr
element_ptr

◆ wlmtk_container_add_element_atop()

void wlmtk_container_add_element_atop ( wlmtk_container_t * container_ptr,
wlmtk_element_t * reference_element_ptr,
wlmtk_element_t * element_ptr )

Adds element_ptr to the container atop the reference's position.

If reference_element_ptr is NULL, the element will be added at the back.

Parameters
container_ptr
reference_element_ptrMust be an element of this container.
element_ptr

◆ wlmtk_container_create_fake_parent()

wlmtk_container_t * wlmtk_container_create_fake_parent ( void )

Constructor for a fake container with a scene tree.

◆ wlmtk_container_destroy_fake_parent()

void wlmtk_container_destroy_fake_parent ( wlmtk_container_t * container_ptr)

Destructor for that fake container.

◆ wlmtk_container_extend()

wlmtk_container_vmt_t wlmtk_container_extend ( wlmtk_container_t * container_ptr,
const wlmtk_container_vmt_t * container_vmt_ptr )

Extends the container's virtual methods.

Parameters
container_ptr
container_vmt_ptr
Returns
The previous virtual method table.

◆ wlmtk_container_fini()

void wlmtk_container_fini ( wlmtk_container_t * container_ptr)

Un-initializes the container.

Any element still in elements will be destroyed.

Parameters
container_ptr

◆ wlmtk_container_init()

bool wlmtk_container_init ( wlmtk_container_t * container_ptr,
wlmtk_env_t * env_ptr )

Initializes the container with the provided virtual method table.

Parameters
container_ptr
env_ptr
Returns
true on success.

◆ wlmtk_container_init_attached()

bool wlmtk_container_init_attached ( wlmtk_container_t * container_ptr,
wlmtk_env_t * env_ptr,
struct wlr_scene_tree * root_wlr_scene_tree_ptr )

Initializes the container, and attach to WLR sene graph.

Parameters
container_ptr
env_ptr
root_wlr_scene_tree_ptr
Returns
true on success.

◆ wlmtk_container_raise_element_to_top()

void wlmtk_container_raise_element_to_top ( wlmtk_container_t * container_ptr,
wlmtk_element_t * element_ptr )

Places element_ptr at the top (head) of the container.

Expects that container_ptr is element_ptr's parent container.

Parameters
container_ptr
element_ptr

◆ wlmtk_container_remove_element()

void wlmtk_container_remove_element ( wlmtk_container_t * container_ptr,
wlmtk_element_t * element_ptr )

Removes element_ptr from the container.

Expects that container_ptr is element_ptr's parent container.

Parameters
container_ptr
element_ptr

◆ wlmtk_container_set_keyboard_focus_element()

void wlmtk_container_set_keyboard_focus_element ( wlmtk_container_t * container_ptr,
wlmtk_element_t * element_ptr )

Reports element_ptr as having keyboard focus, and registers it as such in this container. Will propagate wlmtk_container_t::super_element to this container's parent as element having keyboard focus.

Parameters
container_ptr
element_ptr

◆ wlmtk_container_update_pointer_focus()

void wlmtk_container_update_pointer_focus ( wlmtk_container_t * container_ptr)

Updates pointer focus of the container.

Parameters
container_ptr

◆ wlmtk_container_wlr_scene_tree()

struct wlr_scene_tree * wlmtk_container_wlr_scene_tree ( wlmtk_container_t * container_ptr)

Returns the wlroots scene graph tree for this node.

Private: Should be called only by wlmtk_element_t.

Parameters
container_ptr
Returns
The scene tree, or NULL if not attached to a scene graph.

Variable Documentation

◆ container_element_vmt

const wlmtk_element_vmt_t container_element_vmt
static
Initial value:
= {
}
static struct wlr_scene_node * _wlmtk_container_element_create_scene_node(wlmtk_element_t *element_ptr, struct wlr_scene_tree *wlr_scene_tree_ptr)
Definition container.c:348
static void _wlmtk_container_element_keyboard_blur(wlmtk_element_t *element_ptr)
Definition container.c:606
static bool _wlmtk_container_element_pointer_axis(wlmtk_element_t *element_ptr, struct wlr_pointer_axis_event *wlr_pointer_axis_event_ptr)
Definition container.c:582
static bool _wlmtk_container_element_pointer_button(wlmtk_element_t *element_ptr, const wlmtk_button_event_t *button_event_ptr)
Definition container.c:506
static void _wlmtk_container_element_get_pointer_area(wlmtk_element_t *element_ptr, int *left_ptr, int *top_ptr, int *right_ptr, int *bottom_ptr)
Definition container.c:434
static bool _wlmtk_container_element_pointer_motion(wlmtk_element_t *element_ptr, double x, double y, uint32_t time_msec)
Definition container.c:482
static void _wlmtk_container_element_pointer_enter(wlmtk_element_t *element_ptr)
Definition container.c:598
static bool _wlmtk_container_element_keyboard_event(wlmtk_element_t *element_ptr, struct wlr_keyboard_key_event *wlr_keyboard_key_event_ptr, const xkb_keysym_t *key_syms, size_t key_syms_count, uint32_t modifiers)
Definition container.c:619
static void _wlmtk_container_element_get_dimensions(wlmtk_element_t *element_ptr, int *left_ptr, int *top_ptr, int *right_ptr, int *bottom_ptr)
Definition container.c:387

Virtual method table for the container's super class: Element.

◆ container_vmt

const wlmtk_container_vmt_t container_vmt
static
Initial value:
= {
}
static void _wlmtk_container_update_layout(wlmtk_container_t *container_ptr)
Definition container.c:739

Default virtual method table. Initializes non-abstract methods.

◆ wlmtk_container_test_cases

const bs_test_case_t wlmtk_container_test_cases[]
Initial value:
= {
{ 1, "init_fini", test_init_fini },
{ 1, "add_remove", test_add_remove },
{ 1, "add_remove_with_scene_graph", test_add_remove_with_scene_graph },
{ 1, "add_with_raise", test_add_with_raise },
{ 1, "pointer_motion", test_pointer_motion },
{ 1, "pointer_focus", test_pointer_focus },
{ 1, "pointer_focus_move", test_pointer_focus_move },
{ 1, "pointer_focus_layered", test_pointer_focus_layered },
{ 1, "pointer_button", test_pointer_button },
{ 1, "pointer_axis", test_pointer_axis },
{ 1, "keyboard_event", test_keyboard_event },
{ 1, "keyboard_focus", test_keyboard_focus },
{ 0, NULL, NULL }
}
static void test_pointer_motion(bs_test_t *test_ptr)
Definition container.c:1084
static void test_add_with_raise(bs_test_t *test_ptr)
Definition container.c:1012
static void test_pointer_focus_move(bs_test_t *test_ptr)
Definition container.c:1330
static void test_pointer_focus(bs_test_t *test_ptr)
Definition container.c:1239
static void test_keyboard_focus(bs_test_t *test_ptr)
Definition container.c:1648
static void test_keyboard_event(bs_test_t *test_ptr)
Definition container.c:1607
static void test_pointer_button(bs_test_t *test_ptr)
Definition container.c:1449
static void test_pointer_focus_layered(bs_test_t *test_ptr)
Definition container.c:1372
static void test_add_remove_with_scene_graph(bs_test_t *test_ptr)
Definition container.c:903
static void test_add_remove(bs_test_t *test_ptr)
Definition container.c:851
static void test_init_fini(bs_test_t *test_ptr)
Definition container.c:835
static void test_pointer_axis(bs_test_t *test_ptr)
Definition container.c:1555

Unit tests for the container.