wlmaker
Loading...
Searching...
No Matches
Classes | Macros | Functions | Variables
root_menu.c File Reference
#include "root_menu.h"
#include <inttypes.h>
#include <libbase/libbase.h>
#include <libbase/plist.h>
#include <limits.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_scene.h>
#include "../etc/root_menu.h"
#include "action.h"
#include "action_item.h"
#include "config.h"
#include "subprocess_monitor.h"
Include dependency graph for root_menu.c:

Classes

struct  _wlmaker_root_menu_t
 
struct  wlmaker_root_menu_generator_t
 

Functions

static void _wlmaker_root_menu_content_request_close (wlmtk_content_t *content_ptr)
 
static void _wlmaker_root_menu_content_set_activated (wlmtk_content_t *content_ptr, bool activated)
 
static void _wlmaker_root_menu_handle_menu_open_changed (struct wl_listener *listener_ptr, void *data_ptr)
 
static void _wlmaker_root_menu_handle_request_close (struct wl_listener *listener_ptr, void *data_ptr)
 
static bool _wlmaker_root_menu_init_menu_from_array (wlmtk_menu_t *menu_ptr, bspl_array_t *array_ptr, const wlmtk_menu_style_t *menu_style_ptr, wlmaker_server_t *server_ptr)
 
static bool _wlmaker_root_menu_populate_menu_items_from_array (wlmtk_menu_t *menu_ptr, bspl_array_t *array_ptr, const wlmtk_menu_style_t *menu_style_ptr, wlmaker_server_t *server_ptr)
 
static bool _wlmaker_root_menu_populate_menu_items_from_file (wlmtk_menu_t *menu_ptr, const char *filename_ptr, const wlmtk_menu_style_t *menu_style_ptr, wlmaker_server_t *server_ptr)
 
static bool _wlmaker_root_menu_populate_menu_items_from_generator (wlmtk_menu_t *menu_ptr, const char *command_ptr, const wlmtk_menu_style_t *menu_style_ptr, wlmaker_server_t *server_ptr)
 
static void _wlmaker_root_menu_generator_destroy (wlmaker_root_menu_generator_t *gen_menu_ptr)
 
static void _wlmaker_root_menu_generator_handle_menu_destroy (struct wl_listener *listener_ptr, void *data_ptr)
 
static void _wlmaker_root_menu_generator_handle_terminated (void *userdata_ptr, wlmaker_subprocess_handle_t *subprocess_handle_ptr, int state, int code)
 
static wlmtk_menu_item_t_wlmaker_root_menu_create_item_from_array (bspl_array_t *item_array_ptr, const wlmtk_menu_style_t *menu_style_ptr, wlmaker_server_t *server_ptr)
 
static wlmtk_menu_item_t_wlmaker_root_menu_create_disabled_item (const wlmtk_menu_item_style_t *style_ptr, const char *fmt_ptr,...) __ARG_PRINTF__(2
 
wlmaker_root_menu_twlmaker_root_menu_create (wlmaker_server_t *server_ptr, const char *arg_root_menu_file_ptr, const wlmtk_window_style_t *window_style_ptr, const wlmtk_menu_style_t *menu_style_ptr)
 
void wlmaker_root_menu_destroy (wlmaker_root_menu_t *root_menu_ptr)
 
wlmtk_window_twlmaker_root_menu_window (wlmaker_root_menu_t *root_menu_ptr)
 
wlmtk_menu_twlmaker_root_menu_menu (wlmaker_root_menu_t *root_menu_ptr)
 
static void test_default_menu (bs_test_t *test_ptr)
 
static void test_generated_menu (bs_test_t *test_ptr)
 

Variables

static wlmtk_menu_item_t static const wlmtk_content_vmt_t _wlmaker_root_menu_content_vmt
 
static const char * _wlmaker_root_menu_fname_ptrs []
 
static const char * _wlmaker_root_menu_statement_include = "IncludePlistMenu"
 
static const char * _wlmaker_root_menu_statement_generate = "GeneratePlistMenu"
 
struct wl_display * _wlmaker_root_menu_test_wl_display_ptr = NULL
 
const bs_test_case_t wlmaker_root_menu_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

◆ _wlmaker_root_menu_content_request_close()

void _wlmaker_root_menu_content_request_close ( wlmtk_content_t content_ptr)
static

Implements wlmtk_content_vmt_t::request_close. Closes root menu.

◆ _wlmaker_root_menu_content_set_activated()

void _wlmaker_root_menu_content_set_activated ( wlmtk_content_t content_ptr,
bool  activated 
)
static

Imlements wlmtk_content_vmt_t::set_activated. Gets keyboard focus.

◆ _wlmaker_root_menu_create_disabled_item()

wlmtk_menu_item_t * _wlmaker_root_menu_create_disabled_item ( const wlmtk_menu_item_style_t style_ptr,
const char *  fmt_ptr,
  ... 
)
static

Creates a disabled menu item as a means to display generator state.

Parameters
style_ptr
fmt_ptr
Returns
the disabled menu item, or NULL on error.

◆ _wlmaker_root_menu_create_item_from_array()

wlmtk_menu_item_t * _wlmaker_root_menu_create_item_from_array ( bspl_array_t *  item_array_ptr,
const wlmtk_menu_style_t menu_style_ptr,
wlmaker_server_t server_ptr 
)
static

Creates a menu item from the Plist array.

The Plist array either defines a menu action item, where the array elements are (Title, ActionName, OptionalActionArg). Or, it defines a submenu, as specified in _wlmaker_root_menu_init_menu_from_array.

For the list of permitted ActionName values, see wlmaker_action_desc.

Parameters
item_array_ptr
menu_style_ptr
server_ptr
Returns
The menu item, or NULL on error.

◆ _wlmaker_root_menu_generator_destroy()

void _wlmaker_root_menu_generator_destroy ( wlmaker_root_menu_generator_t generator_ptr)
static

Dtor for the menu generator.

◆ _wlmaker_root_menu_generator_handle_menu_destroy()

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

Handles wlmtk_menu_events_t::destroy. Calls dtor.

◆ _wlmaker_root_menu_generator_handle_terminated()

void _wlmaker_root_menu_generator_handle_terminated ( void *  userdata_ptr,
wlmaker_subprocess_handle_t subprocess_handle_ptr,
int  state,
int  code 
)
static

Handler for when the subprocess is terminated.

◆ _wlmaker_root_menu_handle_menu_open_changed()

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

Handles wlmtk_menu_events_t::open_changed. Unmaps window on close.

◆ _wlmaker_root_menu_handle_request_close()

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

Listens to wlmtk_menu_events_t::request_close. Closes the menu.

◆ _wlmaker_root_menu_init_menu_from_array()

bool _wlmaker_root_menu_init_menu_from_array ( wlmtk_menu_t menu_ptr,
bspl_array_t *  array_ptr,
const wlmtk_menu_style_t menu_style_ptr,
wlmaker_server_t server_ptr 
)
static

Initializes the menu from the menu configuration array.

The menu configuration is a Plist array. The first item is the menu's title, while the second item defines the nature of the menu configuration:

It can define a set of menu items, in form of Plist arrays:

("Menu Title",
  ("Item 1", None),
  ("Item 2", None)
)

Or, it is a definition to include a Plist menu:

("Include", IncludePlistMenu, "tests/data/menu.plist")

Or, it is a definition to generate a Plist menu:

("Include", GeneratePlistMenu, "cat tests/data/menu.plist")
Parameters
menu_ptr
array_ptr
menu_style_ptr
server_ptr
Returns
true on success.

◆ _wlmaker_root_menu_populate_menu_items_from_array()

bool _wlmaker_root_menu_populate_menu_items_from_array ( wlmtk_menu_t menu_ptr,
bspl_array_t *  array_ptr,
const wlmtk_menu_style_t menu_style_ptr,
wlmaker_server_t server_ptr 
)
static

Populates the menu's items from the Plist array. This handles the case of a menu configuration that specifies the menu items as a Plist array.

The first item of array_ptr is the menu's title, and each further item is expected to be another Plist array, defining a menu item.

Parameters
menu_ptr
array_ptr
menu_style_ptr
server_ptr
Returns
true on success

◆ _wlmaker_root_menu_populate_menu_items_from_file()

bool _wlmaker_root_menu_populate_menu_items_from_file ( wlmtk_menu_t menu_ptr,
const char *  filename_ptr,
const wlmtk_menu_style_t menu_style_ptr,
wlmaker_server_t server_ptr 
)
static

Loads a Plist array from file and populates the menu's items from it.

Parameters
menu_ptr
filename_ptr
menu_style_ptr
server_ptr
Returns
true on success

◆ _wlmaker_root_menu_populate_menu_items_from_generator()

bool _wlmaker_root_menu_populate_menu_items_from_generator ( wlmtk_menu_t menu_ptr,
const char *  command_ptr,
const wlmtk_menu_style_t menu_style_ptr,
wlmaker_server_t server_ptr 
)
static

Launches a subprocess, to populate the menu's items.

Uses a wlmaker_root_menu_generator_t to track state of the subprocess and to tie it with the menu's lifecycle.

Parameters
menu_ptr
command_ptr
menu_style_ptr
server_ptr
Returns
true on success

◆ test_default_menu()

void test_default_menu ( bs_test_t *  test_ptr)
static

Verifies that the compiled-in configuration translates into a menu.

◆ test_generated_menu()

void test_generated_menu ( bs_test_t *  test_ptr)
static

Verifies that an example menu with generator is translated.

◆ wlmaker_root_menu_create()

wlmaker_root_menu_t * wlmaker_root_menu_create ( wlmaker_server_t server_ptr,
const char *  arg_root_menu_file_ptr,
const wlmtk_window_style_t window_style_ptr,
const wlmtk_menu_style_t menu_style_ptr 
)

Creates a root menu.

Parameters
server_ptr
arg_root_menu_file_ptr
window_style_ptr
menu_style_ptr
Returns
Handle of the root menu, or NULL on error.

◆ wlmaker_root_menu_destroy()

void wlmaker_root_menu_destroy ( wlmaker_root_menu_t root_menu_ptr)

Destroys the root menu.

Parameters
root_menu_ptr

◆ wlmaker_root_menu_menu()

wlmtk_menu_t * wlmaker_root_menu_menu ( wlmaker_root_menu_t root_menu_ptr)
Returns
Pointer to wlmtk_menu_t of the root menu.

◆ wlmaker_root_menu_window()

wlmtk_window_t * wlmaker_root_menu_window ( wlmaker_root_menu_t root_menu_ptr)
Returns
the window holding the root menu.

Variable Documentation

◆ _wlmaker_root_menu_content_vmt

wlmtk_menu_item_t static const wlmtk_content_vmt_t _wlmaker_root_menu_content_vmt
static
Initial value:
= {
}
static void _wlmaker_root_menu_content_request_close(wlmtk_content_t *content_ptr)
Definition root_menu.c:341
static void _wlmaker_root_menu_content_set_activated(wlmtk_content_t *content_ptr, bool activated)
Definition root_menu.c:352

Virtual method of the root menu's window content.

◆ _wlmaker_root_menu_fname_ptrs

const char* _wlmaker_root_menu_fname_ptrs[]
static
Initial value:
= {
"~/.wlmaker-root-menu.plist",
"/usr/share/wlmaker/root-menu.plist",
NULL
}

Lookup paths for the root menu config file.

◆ _wlmaker_root_menu_statement_generate

const char* _wlmaker_root_menu_statement_generate = "GeneratePlistMenu"
static

Indicates to generate the menu using a shell command specified in the following argument.

◆ _wlmaker_root_menu_statement_include

const char* _wlmaker_root_menu_statement_include = "IncludePlistMenu"
static

Indicates to load the file specified in following argument.

◆ _wlmaker_root_menu_test_wl_display_ptr

struct wl_display* _wlmaker_root_menu_test_wl_display_ptr = NULL

Unit test injector: struct wl_display that will be terminated when subprocess terminates. Must be NULL when not for in unit tests.

◆ wlmaker_root_menu_test_cases

const bs_test_case_t wlmaker_root_menu_test_cases[]
Initial value:
= {
{ 1, "default_menu", test_default_menu },
{ 1, "generated_menu", test_generated_menu },
{ 0, NULL, NULL }
}
static void test_generated_menu(bs_test_t *test_ptr)
Definition root_menu.c:908
static void test_default_menu(bs_test_t *test_ptr)
Definition root_menu.c:894

Unit test cases.