Skip to content

Commit

Permalink
parent 856ba4a
Browse files Browse the repository at this point in the history
author Philipp Kaeser <[email protected]> 1736885410 +0000
committer Philipp Kaeser <[email protected]> 1739545497 +0100

Enables/disables window menu items according to window's state.
  • Loading branch information
phkaeser committed Feb 14, 2025
1 parent 856ba4a commit 2fc157f
Show file tree
Hide file tree
Showing 19 changed files with 398 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-for-bookworm-wlroots-018.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
export PKG_CONFIG_PATH="${{ env.INSTALL_PKGCONFIG_PATH }}"
export LD_LIBRARY_PATH="${{ env.INSTALL_LIBRARY_PATH }}"
export PATH="${PATH}:${{ env.INSTALL_PATH }}/bin"
cmake -DCMAKE_INSTALL_PREFIX:PATH=${{ env.INSTALL_PATH }} -B build/
cmake -DCMAKE_INSTALL_PREFIX:PATH=${{ env.INSTALL_PATH }} -Dconfig_WERROR=ON -B build/
- name: Build wlmaker.
run: |
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/build-for-fedora41.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build for Fedora Linux 41

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build_matrix:
strategy:
matrix:
compiler: [ "gcc", "clang" ]
runs-on: ubuntu-latest
container:
image: fedora:41

steps:
- name: Install package dependencies.
run: |
dnf -y upgrade
dnf -y install \
bison \
clang \
cmake \
flex \
gcc \
git \
cairo-devel \
ncurses-devel \
wlroots-devel \
pkg-config \
plantuml \
wayland-protocols-devel \
xwayland-run
- name: Checkout code, including git submodules.
uses: actions/checkout@v3
with:
# Not using 'recursive' prevents fetching extra submodules below
# dependencies/. These are only needed to build wlroots from source.
submodules: true

- name: Configure wlmaker through CMake.
run: |
export CC="${{ matrix.compiler }}"
cmake -B build/ -Dconfig_WERROR=ON
- name: Build wlmaker.
run: |
export CC="${{ matrix.compiler }}"
cmake --build build/
- name: Run all tests.
run: |
ctest --test-dir build/ --build-run-dir build/ -V
2 changes: 1 addition & 1 deletion .github/workflows/build-for-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Configure wlmaker through CMake.
run: |
export CC="${{ matrix.compiler }}"
cmake -B build/
cmake -B build/ -Dconfig_WERROR=ON
- name: Build wlmaker.
run: |
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[submodule "submodules/libbase"]
path = submodules/libbase
url = ../libbase
url = https://github.com/phkaeser/libbase.git
branch = main
update = rebase
[submodule "examples/gtk-layer-shell"]
path = examples/gtk-layer-shell
url = https://github.com/wmww/gtk-layer-shell.git
[submodule "dependencies"]
path = dependencies
url = git@github.com:phkaeser/wlmaker-dependencies.git
path = dependencies
url = https://github.com/phkaeser/wlmaker-dependencies.git
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
#
# Default arguments:
# cmake -DCMAKE_INSTALL_PREFIX:PATH=${HOME}/.local -Dconfig_DOXYGEN_CRITICAL=ON -B build
# cmake -DCMAKE_INSTALL_PREFIX:PATH=${HOME}/.local -Dconfig_DOXYGEN_CRITICAL=ON -Dconfig_WERROR=ON -B build
# CC=clang cmake -DCMAKE_INSTALL_PREFIX:PATH=${HOME}/.local -Dconfig_DOXYGEN_CRITICAL=ON -B build-clang

CMAKE_MINIMUM_REQUIRED(VERSION 3.13)
Expand Down Expand Up @@ -69,10 +69,14 @@ ENDIF(NOT WLROOTS_FOUND)
OPTION(config_DEBUG "Include debugging information" ON)
OPTION(config_OPTIM "Optimizations" OFF)
OPTION(config_DOXYGEN_CRITICAL "Whether to fail on doxygen warnings" OFF)
OPTION(config_WERROR "Make all compiler warnings into errors." OFF)

# Toplevel compile options, for GCC and clang.
IF(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
ADD_COMPILE_OPTIONS(-Wall -Wextra -Werror)
ADD_COMPILE_OPTIONS(-Wall -Wextra)
IF(config_WERROR)
ADD_COMPILE_OPTIONS(-Werror)
ENDIF(config_WERROR)

IF(config_DEBUG)
ADD_COMPILE_OPTIONS(-ggdb -DDEBUG)
Expand Down
1 change: 0 additions & 1 deletion apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ TARGET_INCLUDE_DIRECTORIES(example_toplevel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
TARGET_LINK_LIBRARIES(example_toplevel libwlclient)

INSTALL(TARGETS wlmclock DESTINATION bin)
INSTALL(TARGETS example_toplevel DESTINATION bin)
2 changes: 1 addition & 1 deletion doc/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Support for visual effects to improve usability, but not for pure show.
* [done] Available also for X11 windows.
* Available as (hardcoded) application menu.
* Menu with submenus.
* Window menu adapting to window state.
* [done] Window menu adapting to window state.
(Eg. "Maximize" shown when not maximized, otherwise: "restore".)
* When positioning the root menu, keep it entirely within the desktop area.

Expand Down
51 changes: 50 additions & 1 deletion src/action_item.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@ wlmaker_action_item_t *wlmaker_action_item_create(
return action_item_ptr;
}

/* ------------------------------------------------------------------------- */
wlmaker_action_item_t *wlmaker_action_item_create_from_desc(
const wlmaker_action_item_desc_t *desc_ptr,
void *dest_ptr,
const wlmtk_menu_item_style_t *style_ptr,
wlmaker_server_t *server_ptr,
wlmtk_env_t *env_ptr)
{
wlmaker_action_item_t *action_item_ptr = wlmaker_action_item_create(
desc_ptr->text_ptr,
style_ptr,
desc_ptr->action,
server_ptr,
env_ptr);
if (NULL == action_item_ptr) return NULL;

*(wlmaker_action_item_t**)(
(uint8_t*)dest_ptr + desc_ptr->destination_ofs) = action_item_ptr;
return action_item_ptr;
}

/* ------------------------------------------------------------------------- */
void wlmaker_action_item_destroy(wlmaker_action_item_t *action_item_ptr)
{
Expand Down Expand Up @@ -134,4 +155,32 @@ void _wlmaker_action_item_clicked(wlmtk_menu_item_t *menu_item_ptr)
}
}

/* == End of action_item.c ================================================== */
/* == Unit tests =========================================================== */

static void _wlmaker_action_item_test_create(bs_test_t *test_ptr);

/** Test cases for action items. */
const bs_test_case_t wlmaker_action_item_test_cases[] = {
{ 1, "create", _wlmaker_action_item_test_create },
{ 0, NULL, NULL },
};

/* ------------------------------------------------------------------------- */
/** Tests creation the menu item. */
void _wlmaker_action_item_test_create(bs_test_t *test_ptr)
{
wlmaker_action_item_t *ai_ptr = NULL;
wlmaker_action_item_desc_t desc = { "text", 42, 0 };
wlmtk_menu_item_style_t style = {};
wlmaker_server_t server = {};

BS_TEST_VERIFY_TRUE(
test_ptr,
wlmaker_action_item_create_from_desc(
&desc, &ai_ptr, &style, &server, NULL));

BS_TEST_VERIFY_NEQ(test_ptr, NULL, ai_ptr);
wlmaker_action_item_destroy(ai_ptr);
}

/* == End of action_item.c ================================================= */
34 changes: 34 additions & 0 deletions src/action_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ typedef struct _wlmaker_action_item_t wlmaker_action_item_t;
extern "C" {
#endif // __cplusplus

/** Descriptor for creating a menu item triggering an action. */
typedef struct {
/** Text for the menu item. */
const char *text_ptr;
/** The action to trigger. */
wlmaker_action_t action;
/**
* Where to store the @ref wlmaker_action_item_t, relative to the
* `dest_ptr` argument of @ref wlmaker_action_item_create_from_desc.
*/
size_t destination_ofs;
} wlmaker_action_item_desc_t;

/**
* Creates a menu item that triggers a @ref wlmaker_action_t.
*
Expand All @@ -49,6 +62,24 @@ wlmaker_action_item_t *wlmaker_action_item_create(
wlmaker_server_t *server_ptr,
wlmtk_env_t *env_ptr);

/**
* Creates a menu item triggering an action item from a descriptor.
*
* @param desc_ptr
* @param dest_ptr
* @param style_ptr
* @param server_ptr
* @param env_ptr
*
* @return Pointer to the item's handle or NULL on error.
*/
wlmaker_action_item_t *wlmaker_action_item_create_from_desc(
const wlmaker_action_item_desc_t *desc_ptr,
void *dest_ptr,
const wlmtk_menu_item_style_t *style_ptr,
wlmaker_server_t *server_ptr,
wlmtk_env_t *env_ptr);

/**
* Destroys the action-triggering menu item.
*
Expand All @@ -60,6 +91,9 @@ void wlmaker_action_item_destroy(wlmaker_action_item_t *action_item_ptr);
wlmtk_menu_item_t *wlmaker_action_item_menu_item(
wlmaker_action_item_t *action_item_ptr);

/** Unit test cases. */
extern const bs_test_case_t wlmaker_action_item_test_cases[];

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
Expand Down
Loading

0 comments on commit 2fc157f

Please sign in to comment.