Skip to content

Commit

Permalink
Allow compilation without Wayland support (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
rcaelers committed Mar 5, 2024
1 parent 88ef702 commit bc0055c
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 42 deletions.
1 change: 1 addition & 0 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#cmakedefine HAVE_TESTS
#cmakedefine HAVE_TRACING
#cmakedefine HAVE_UNFOLD_AUTO_UPDATE
#cmakedefine HAVE_WAYLAND
#cmakedefine HAVE_XFCE4
#cmakedefine HAVE_XRECORD
#cmakedefine PLATFORM_OS_MACOS
Expand Down
28 changes: 17 additions & 11 deletions libs/input-monitor/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,31 @@ if (PLATFORM_OS_UNIX)
unix/XScreenSaverMonitor.cc
unix/UnixInputMonitorFactory.cc
unix/MutterInputMonitor.cc
unix/WaylandInputMonitor.cc
${CMAKE_CURRENT_BINARY_DIR}/ext-idle-notify-v1.c
)

target_include_directories(workrave-libs-input-monitor PRIVATE ${CMAKE_SOURCE_DIR}/libs/input-monitor/src/unix)

if (HAVE_GTK)
target_include_directories(workrave-libs-input-monitor PRIVATE ${GTK_INCLUDE_DIRS})
target_link_libraries(workrave-libs-input-monitor ${GTK_LIBRARIES})
target_link_libraries(workrave-libs-input-monitor ${X11_X11_LIB} ${X11_Xtst_LIB} ${X11_Xss_LIB})
endif()
target_link_libraries(workrave-libs-input-monitor ${WAYLAND_CLIENT_LIBRARIES})

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ext-idle-notify-v1.c ${CMAKE_CURRENT_BINARY_DIR}/ext-idle-notify-v1-client.h
COMMAND ${WAYLAND_SCANNER} private-code ${CMAKE_CURRENT_SOURCE_DIR}/unix/protocols/ext-idle-notify-v1.xml ${CMAKE_CURRENT_BINARY_DIR}/ext-idle-notify-v1.c
COMMAND ${WAYLAND_SCANNER} client-header ${CMAKE_CURRENT_SOURCE_DIR}/unix/protocols/ext-idle-notify-v1.xml ${CMAKE_CURRENT_BINARY_DIR}/ext-idle-notify-v1-client.h
DEPENDS unix/protocols/ext-idle-notify-v1.xml
VERBATIM
)

if (HAVE_WAYLAND)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ext-idle-notify-v1.c ${CMAKE_CURRENT_BINARY_DIR}/ext-idle-notify-v1-client.h
COMMAND ${WAYLAND_SCANNER} private-code ${CMAKE_CURRENT_SOURCE_DIR}/unix/protocols/ext-idle-notify-v1.xml ${CMAKE_CURRENT_BINARY_DIR}/ext-idle-notify-v1.c
COMMAND ${WAYLAND_SCANNER} client-header ${CMAKE_CURRENT_SOURCE_DIR}/unix/protocols/ext-idle-notify-v1.xml ${CMAKE_CURRENT_BINARY_DIR}/ext-idle-notify-v1-client.h
DEPENDS unix/protocols/ext-idle-notify-v1.xml
VERBATIM
)
target_sources(workrave-libs-input-monitor PRIVATE
unix/WaylandInputMonitor.cc
${CMAKE_CURRENT_BINARY_DIR}/ext-idle-notify-v1.c
)
target_link_libraries(workrave-libs-input-monitor ${WAYLAND_CLIENT_LIBRARIES})
endif()

target_include_directories(workrave-libs-input-monitor PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
endif()

Expand Down
7 changes: 6 additions & 1 deletion libs/input-monitor/src/unix/UnixInputMonitorFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
#include "X11InputMonitor.hh"
#include "XScreenSaverMonitor.hh"
#include "MutterInputMonitor.hh"
#include "WaylandInputMonitor.hh"

#if defined(HAVE_WAYLAND)
# include "WaylandInputMonitor.hh"
#endif

using namespace std;
using namespace workrave;
Expand Down Expand Up @@ -111,10 +114,12 @@ UnixInputMonitorFactory::create_monitor(MonitorCapability capability)
{
monitor = IInputMonitor::Ptr(new MutterInputMonitor());
}
#if defined(HAVE_WAYLAND)
else if (monitor_method == "wayland")
{
monitor = IInputMonitor::Ptr(new WaylandInputMonitor());
}
#endif

initialized = monitor->init();

Expand Down
12 changes: 6 additions & 6 deletions ui/app/toolkits/gtkmm/BreakWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
# include "core/ICore.hh"
#elif defined(PLATFORM_OS_UNIX)
# include "desktop-window.h"
#endif
#if defined(HAVE_WAYLAND)
# include "WaylandWindowManager.hh"
#endif

Expand All @@ -76,7 +78,7 @@ BreakWindow::BreakWindow(std::shared_ptr<IApplicationContext> app,
{
TRACE_ENTRY();

#if defined(PLATFORM_OS_UNIX)
#if defined(HAVE_WAYLAND)
if (Platform::running_on_wayland())
{
auto wm = std::make_shared<WaylandWindowManager>();
Expand Down Expand Up @@ -146,9 +148,7 @@ BreakWindow::BreakWindow(std::shared_ptr<IApplicationContext> app,
if (WindowsForceFocus::GetForceFocusValue())
initial_ignore_activity = true;

app->get_configurator()->get_value_with_default("advanced/force_focus_on_break_start",
force_focus_on_break_start,
true);
app->get_configurator()->get_value_with_default("advanced/force_focus_on_break_start", force_focus_on_break_start, true);
#endif

auto core = app->get_core();
Expand Down Expand Up @@ -695,7 +695,7 @@ BreakWindow::start()
// Otherwise, there is not gobj()...
realize_if_needed();

#if defined(PLATFORM_OS_UNIX)
#if defined(HAVE_WAYLAND)
if (window_manager)
{
window_manager->init_surface(*this, head.get_monitor(), true);
Expand Down Expand Up @@ -764,7 +764,7 @@ BreakWindow::stop()

hide();

#if defined(PLATFORM_OS_UNIX)
#if defined(HAVE_WAYLAND)
if (window_manager)
{
window_manager->clear_surfaces();
Expand Down
4 changes: 2 additions & 2 deletions ui/app/toolkits/gtkmm/BreakWindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#if defined(PLATFORM_OS_WINDOWS)
class DesktopWindow;
#endif
#if defined(PLATFORM_OS_UNIX)
#if defined(HAVE_WAYLAND)
# include "platforms/unix/WaylandWindowManager.hh"
#endif

Expand Down Expand Up @@ -154,7 +154,7 @@ private:
bool force_focus_on_break_start{false};
long parent{0};
#endif
#if defined(PLATFORM_OS_UNIX)
#if defined(HAVE_WAYLAND)
std::shared_ptr<WaylandWindowManager> window_manager;
#endif

Expand Down
42 changes: 24 additions & 18 deletions ui/app/toolkits/gtkmm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,32 @@ if (PLATFORM_OS_UNIX)
platforms/unix/desktop-window.c
platforms/unix/gtktrayicon.c
platforms/unix/UnixLocker.cc
platforms/unix/WaylandWindowManager.cc
${CMAKE_CURRENT_BINARY_DIR}/wlr-layer-shell-unstable-v1.c
${CMAKE_CURRENT_BINARY_DIR}/xdg-shell.c

)

if (HAVE_WAYLAND)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/wlr-layer-shell-unstable-v1.c ${CMAKE_CURRENT_BINARY_DIR}/wlr-layer-shell-unstable-v1-client.h
COMMAND ${WAYLAND_SCANNER} private-code ${CMAKE_CURRENT_SOURCE_DIR}/platforms/unix/protocols/wlr-layer-shell-unstable-v1.xml ${CMAKE_CURRENT_BINARY_DIR}/wlr-layer-shell-unstable-v1.c
COMMAND ${WAYLAND_SCANNER} client-header ${CMAKE_CURRENT_SOURCE_DIR}/platforms/unix/protocols/wlr-layer-shell-unstable-v1.xml ${CMAKE_CURRENT_BINARY_DIR}/wlr-layer-shell-unstable-v1-client.h
DEPENDS platforms/unix/protocols/wlr-layer-shell-unstable-v1.xml
VERBATIM
)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell.c ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client.h
COMMAND ${WAYLAND_SCANNER} private-code ${CMAKE_CURRENT_SOURCE_DIR}/platforms/unix/protocols/xdg-shell.xml ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell.c
COMMAND ${WAYLAND_SCANNER} client-header ${CMAKE_CURRENT_SOURCE_DIR}/platforms/unix/protocols/xdg-shell.xml ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client.h
DEPENDS platforms/unix/protocols/xdg-shell.xml
VERBATIM
)

target_sources(workrave-toolkit-gtkmm PRIVATE
platforms/unix/WaylandWindowManager.cc
${CMAKE_CURRENT_BINARY_DIR}/wlr-layer-shell-unstable-v1.c
${CMAKE_CURRENT_BINARY_DIR}/xdg-shell.c)
endif()

if (HAVE_DBUSMENU)
target_sources(workrave-toolkit-gtkmm PRIVATE platforms/unix/DbusMenu.cc)
endif()
Expand All @@ -62,21 +83,6 @@ if (PLATFORM_OS_UNIX)

target_include_directories(workrave-toolkit-gtkmm PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/platforms/unix ${CMAKE_CURRENT_SOURCE_DIR}/platforms/unix/protocols)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/wlr-layer-shell-unstable-v1.c ${CMAKE_CURRENT_BINARY_DIR}/wlr-layer-shell-unstable-v1-client.h
COMMAND ${WAYLAND_SCANNER} private-code ${CMAKE_CURRENT_SOURCE_DIR}/platforms/unix/protocols/wlr-layer-shell-unstable-v1.xml ${CMAKE_CURRENT_BINARY_DIR}/wlr-layer-shell-unstable-v1.c
COMMAND ${WAYLAND_SCANNER} client-header ${CMAKE_CURRENT_SOURCE_DIR}/platforms/unix/protocols/wlr-layer-shell-unstable-v1.xml ${CMAKE_CURRENT_BINARY_DIR}/wlr-layer-shell-unstable-v1-client.h
DEPENDS platforms/unix/protocols/wlr-layer-shell-unstable-v1.xml
VERBATIM
)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell.c ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client.h
COMMAND ${WAYLAND_SCANNER} private-code ${CMAKE_CURRENT_SOURCE_DIR}/platforms/unix/protocols/xdg-shell.xml ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell.c
COMMAND ${WAYLAND_SCANNER} client-header ${CMAKE_CURRENT_SOURCE_DIR}/platforms/unix/protocols/xdg-shell.xml ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client.h
DEPENDS platforms/unix/protocols/xdg-shell.xml
VERBATIM
)

target_include_directories(workrave-toolkit-gtkmm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/platforms/unix/)
endif()
Expand Down
6 changes: 3 additions & 3 deletions ui/app/toolkits/gtkmm/PreludeWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ PreludeWindow::PreludeWindow(HeadInfo head, BreakId break_id)
: Gtk::Window(Gtk::WINDOW_POPUP)
{
TRACE_ENTRY();
#if defined(PLATFORM_OS_UNIX)
#if defined(HAVE_WAYLAND)
if (Platform::running_on_wayland())
{
auto wm = std::make_shared<WaylandWindowManager>();
Expand Down Expand Up @@ -137,7 +137,7 @@ PreludeWindow::start()
// Otherwise, there is no gobj()...
realize_if_needed();

#if defined(PLATFORM_OS_UNIX)
#if defined(HAVE_WAYLAND)
if (window_manager)
{
window_manager->init_surface(*this, head.get_monitor(), false);
Expand Down Expand Up @@ -198,7 +198,7 @@ PreludeWindow::stop()
frame->set_frame_flashing(0);
hide();

#if defined(PLATFORM_OS_UNIX)
#if defined(HAVE_WAYLAND)
if (window_manager)
{
window_manager->clear_surfaces();
Expand Down
2 changes: 1 addition & 1 deletion ui/app/toolkits/gtkmm/PreludeWindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private:
// Alignment in Wayland
Gtk::Alignment *align{nullptr};

#if defined(PLATFORM_OS_UNIX)
#if defined(HAVE_WAYLAND)
std::shared_ptr<WaylandWindowManager> window_manager;
#endif
};
Expand Down

0 comments on commit bc0055c

Please sign in to comment.