wlmaker
Loading...
Searching...
No Matches
menu.c File Reference
#include "menu.h"
#include "config.h"
#include <libbase/libbase.h>
#include <linux/input-event-codes.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_xcursor_manager.h>
Include dependency graph for menu.c:

Classes

struct  wlmaker_menu_t
 

Functions

static wlmaker_menu_tmenu_from_interactive (wlmaker_interactive_t *interactive_ptr)
 
static void _menu_enter (wlmaker_interactive_t *interactive_ptr)
 
static void _menu_leave (wlmaker_interactive_t *interactive_ptr)
 
static void _menu_motion (wlmaker_interactive_t *interactive_ptr, double x, double y)
 
static void _menu_focus (wlmaker_interactive_t *interactive_ptr)
 
static void _menu_button (wlmaker_interactive_t *interactive_ptr, double x, double y, struct wlr_pointer_button_event *wlr_pointer_button_event_ptr)
 
static void _menu_destroy (wlmaker_interactive_t *interactive_ptr)
 
static cairo_surface_t * create_background (wlmaker_menu_t *menu_ptr)
 
static bool items_init (wlmaker_menu_t *menu_ptr, const wlmaker_menu_item_descriptor_t *descriptor_ptr, void *callback_ud_ptr)
 
static struct wlr_buffer * create_drawn_buffer (wlmaker_menu_t *menu_ptr)
 
static void redraw_if_needed (wlmaker_menu_t *menu_ptr)
 
static void focus_item (wlmaker_menu_t *menu_ptr, wlmaker_menu_item_t *menu_item_ptr)
 
static void dlnode_draw (bs_dllist_node_t *node_ptr, void *ud_ptr)
 
static bool dlnode_contains (bs_dllist_node_t *node_ptr, void *ud_ptr)
 
static bool dlnode_needs_redraw (bs_dllist_node_t *dlnode_ptr, void *ud_ptr)
 
wlmaker_interactive_twlmaker_menu_create (struct wlr_scene_buffer *wlr_scene_buffer_ptr, wlmaker_cursor_t *cursor_ptr, wlmaker_view_t *view_ptr, const wlmaker_menu_item_descriptor_t *descriptor_ptr, void *callback_ud_ptr)
 
void wlmaker_menu_get_size (wlmaker_interactive_t *interactive_ptr, uint32_t *width_ptr, uint32_t *height_ptr)
 
static void test_create (bs_test_t *test_ptr)
 
static void test_select (bs_test_t *test_ptr)
 

Variables

static const wlmaker_interactive_impl_t wlmaker_interactive_menu_impl
 
const bs_test_case_t wlmaker_menu_test_cases []
 
static const wlmaker_menu_item_descriptor_t test_descriptors []
 

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

◆ _menu_button()

void _menu_button ( wlmaker_interactive_t * interactive_ptr,
double x,
double y,
struct wlr_pointer_button_event * wlr_pointer_button_event_ptr )
static

Interactive callback: Handle cursor button, ie. button press or release.

TODO: Identify menu item that was activated, forward the call.

Parameters
interactive_ptr
x
y
wlr_pointer_button_event_ptr

◆ _menu_destroy()

void _menu_destroy ( wlmaker_interactive_t * interactive_ptr)
static

Destroys the menu interactive.

Parameters
interactive_ptr

◆ _menu_enter()

void _menu_enter ( wlmaker_interactive_t * interactive_ptr)
static

Interactive callback: Cursor enters the menu area.

Will adjust the cursor image to a |left_ptr|. Actual highlighting is done by the _menu_motion call.

Parameters
interactive_ptr

◆ _menu_focus()

void _menu_focus ( wlmaker_interactive_t * interactive_ptr)
static

Interactive callback: Focus state changes.

TODO: Disable the menu when the focus is lost.

Parameters
interactive_ptr

◆ _menu_leave()

void _menu_leave ( wlmaker_interactive_t * interactive_ptr)
static

Interactive callback: Cursor leaves the button area.

Will blur (de-select) any currently focussed menu item.

Parameters
interactive_ptr

◆ _menu_motion()

void _menu_motion ( wlmaker_interactive_t * interactive_ptr,
double x,
double y )
static

Interactive callback: Handle cursor motion.

Parameters
interactive_ptr
xNew cursor x pos, relative to the interactive.
yNew cursor y pos, relative to the interactive.

◆ create_background()

cairo_surface_t * create_background ( wlmaker_menu_t * menu_ptr)
static

Creates the menu's background. Expects menu_items to be populated.

Parameters
menu_ptr
Returns
A pointer to the cairo_surface_t holding the background. Must be destroyed via cairo_surface_destroy().

◆ create_drawn_buffer()

struct wlr_buffer * create_drawn_buffer ( wlmaker_menu_t * menu_ptr)
static

Creates a struct wlr_buffer of suitable size and draws the menu into it.

Parameters
menu_ptr
Returns
A pointer to a struct wlr_buffer.

◆ dlnode_contains()

bool dlnode_contains ( bs_dllist_node_t * node_ptr,
void * ud_ptr )
static

Whether the item at |node_ptr| contains the coordinates at |ud_ptr|.

◆ dlnode_draw()

void dlnode_draw ( bs_dllist_node_t * node_ptr,
void * ud_ptr )
static

Draws |node_ptr| into the cairo_t at |ud_ptr|.

◆ dlnode_needs_redraw()

bool dlnode_needs_redraw ( bs_dllist_node_t * dlnode_ptr,
void * ud_ptr )
static

Whether the item at |node_ptr| needs to be redrawn.

◆ focus_item()

void focus_item ( wlmaker_menu_t * menu_ptr,
wlmaker_menu_item_t * menu_item_ptr )
static

Sets |menu_item_ptr| as the focussed (selected) item, and de-selects any previously selected item.

Parameters
menu_ptr
menu_item_ptrMay be NULL.

◆ items_init()

bool items_init ( wlmaker_menu_t * menu_ptr,
const wlmaker_menu_item_descriptor_t * desc_ptr,
void * callback_ud_ptr )
static

Initializes the menu items, width and height from the given descriptor.

Parameters
menu_ptr
desc_ptr
callback_ud_ptrArgument to provide to item's callbacks.
Returns
true on success.

◆ menu_from_interactive()

wlmaker_menu_t * menu_from_interactive ( wlmaker_interactive_t * interactive_ptr)
static

Cast (with assertion) the |interactive_ptr| to the wlmaker_menu_t.

Parameters
interactive_ptr
Returns
Pointer to the corresponding wlmaker_menu_t

◆ redraw_if_needed()

void redraw_if_needed ( wlmaker_menu_t * menu_ptr)
static

Determines whether any menu item needs a redraw, then redraws if needed.

Parameters
menu_ptr

◆ test_create()

void test_create ( bs_test_t * test_ptr)
static

Tests create and destroy methods of the menu, useful for leak checks.

◆ test_select()

void test_select ( bs_test_t * test_ptr)
static

Tests that the items are selected as desired.

◆ wlmaker_menu_create()

wlmaker_interactive_t * wlmaker_menu_create ( struct wlr_scene_buffer * wlr_scene_buffer_ptr,
wlmaker_cursor_t * cursor_ptr,
wlmaker_view_t * view_ptr,
const wlmaker_menu_item_descriptor_t * descriptor_ptr,
void * callback_ud_ptr )

Creates a menu interactive.

Parameters
wlr_scene_buffer_ptrBuffer scene node to contain the button.
cursor_ptr
view_ptr
descriptor_ptr
callback_ud_ptrArgument to provide to item's callbacks.
Returns
A pointer to the interactive. Must be destroyed via |_menu_destroy|.

◆ wlmaker_menu_get_size()

void wlmaker_menu_get_size ( wlmaker_interactive_t * interactive_ptr,
uint32_t * width_ptr,
uint32_t * height_ptr )

Retrieves the size of the menu.

Parameters
interactive_ptr
width_ptr
height_ptr

Variable Documentation

◆ test_descriptors

const wlmaker_menu_item_descriptor_t test_descriptors[]
static
Initial value:
= {
}
#define WLMAKER_MENU_ITEM_DESCRIPTOR_SENTINEL()
Definition menu_item.h:66
#define WLMAKER_MENU_ITEM_DESCRIPTOR_ENTRY(_label, _callback)
Definition menu_item.h:57

Menu descriptor for unit tests.

◆ wlmaker_interactive_menu_impl

const wlmaker_interactive_impl_t wlmaker_interactive_menu_impl
static
Initial value:
= {
.enter = _menu_enter,
.leave = _menu_leave,
.motion = _menu_motion,
.focus = _menu_focus,
.button = _menu_button,
.destroy = _menu_destroy
}
static void _menu_enter(wlmaker_interactive_t *interactive_ptr)
Definition menu.c:181
static void _menu_motion(wlmaker_interactive_t *interactive_ptr, double x, double y)
Definition menu.c:214
static void _menu_button(wlmaker_interactive_t *interactive_ptr, double x, double y, struct wlr_pointer_button_event *wlr_pointer_button_event_ptr)
Definition menu.c:249
static void _menu_focus(wlmaker_interactive_t *interactive_ptr)
Definition menu.c:234
static void _menu_destroy(wlmaker_interactive_t *interactive_ptr)
Definition menu.c:279
static void _menu_leave(wlmaker_interactive_t *interactive_ptr)
Definition menu.c:198

Implementation: callbacks for the interactive.

◆ wlmaker_menu_test_cases

const bs_test_case_t wlmaker_menu_test_cases[]
Initial value:
= {
{ 1, "create", test_create },
{ 1, "select", test_select },
{ 0, NULL, NULL }
}
static void test_create(bs_test_t *test_ptr)
Definition menu.c:538
static void test_select(bs_test_t *test_ptr)
Definition menu.c:563

Unit tests.