Skip to content

Commit

Permalink
Qt improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rcaelers committed Feb 9, 2025
1 parent ee389c5 commit b0b83b2
Show file tree
Hide file tree
Showing 32 changed files with 507 additions and 80 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,11 @@ if (WIN32)
set (PLATFORM_OS_WINDOWS_NATIVE 1)
endif()

set (HAVE_HARPOON ON)
if (WITH_UI_QT)
set (HAVE_HARPOON OFF)
else()
set (HAVE_HARPOON ON)
endif()

if (NOT MSVC)
find_program(MSYS2_SHELL
Expand Down
18 changes: 13 additions & 5 deletions libs/utils/src/Paths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ using namespace workrave::utils;

namespace
{
using namespace std::string_view_literals;

#ifdef HAVE_APP_QT
constexpr std::string_view app_name = "WorkraveQt"sv;
#else
constexpr std::string_view app_name = "Workrave"sv;
#endif

std::filesystem::path portable_directory;

#if defined(PLATFORM_OS_WINDOWS)
Expand Down Expand Up @@ -230,7 +238,7 @@ Paths::get_config_directories()
try
{
#if defined(PLATFORM_OS_WINDOWS)
directories.push_back(get_home_directory() / "Workrave");
directories.push_back(get_home_directory() / app_name);
directories.push_back(get_application_directory() / "etc");
#endif

Expand Down Expand Up @@ -266,7 +274,7 @@ Paths::get_state_directories()
{
#if defined(PLATFORM_OS_WINDOWS)
directories.push_back(get_application_directory() / "etc");
directories.push_back(get_home_directory() / "Workrave");
directories.push_back(get_home_directory() / app_name);
#endif

#if defined(HAVE_GLIB)
Expand Down Expand Up @@ -378,7 +386,7 @@ Paths::get_state_directory()
{
TRACE_MSG("Using preferred directory");
#if defined(PLATFORM_OS_WINDOWS)
ret = get_home_directory() / "Workrave";
ret = get_home_directory() / app_name;
#elif defined(HAVE_GLIB)
# if GLIB_CHECK_VERSION(2, 72, 0)
const gchar *user_state_dir = g_get_user_state_dir();
Expand Down Expand Up @@ -469,7 +477,7 @@ Paths::get_log_directory()
std::filesystem::path dir = get_home_directory();
if (!dir.empty())
{
dir /= std::filesystem::path("Library") / "Logs" / "Workrave";
dir /= std::filesystem::path("Library") / "Logs" / app_name;
return dir;
}

Expand All @@ -484,7 +492,7 @@ Paths::get_log_directory()
std::filesystem::path dir = get_special_folder(FOLDERID_LocalAppData);
if (!dir.empty())
{
dir /= std::filesystem::path("Workrave") / "Logs";
dir /= std::filesystem::path(app_name) / "Logs";
return dir;
}

Expand Down
2 changes: 2 additions & 0 deletions ui/app/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ Application::init_dbus()
// dialog.set_secondary_text(_("Is Workrave already running?"));
// dialog.show();
// dialog.run();
#if !defined(HAVE_APP_QT)
exit(1);
#endif
}

try
Expand Down
1 change: 0 additions & 1 deletion ui/app/GenericDBusApplet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

namespace
{
constexpr const char *WORKRAVE_APPLET_SERVICE_NAME = "org.workrave.Workrave";
constexpr const char *WORKRAVE_APPLET_SERVICE_IFACE = "org.workrave.AppletInterface";
constexpr const char *WORKRAVE_APPLET_SERVICE_OBJ = "/org/workrave/Workrave/UI";
} // namespace
Expand Down
5 changes: 4 additions & 1 deletion ui/app/platforms/windows/WindowsHarpoonLocker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

#include <cstdint>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <cstdint>

#include "ui/windows/WindowsHarpoonLocker.hh"

#include "input-monitor/Harpoon.hh"
Expand Down Expand Up @@ -58,6 +59,7 @@ WindowsHarpoonLocker::prepare_lock()
text.resize(GetWindowTextLengthA(active_window));
GetWindowTextA(active_window, text.data(), text.size() + 1);
TRACE_MSG("Save active window: {}", text);
spdlog::info("Save active window: {} {}", text, reinterpret_cast<intptr_t>(active_window));
}

void
Expand All @@ -78,6 +80,7 @@ WindowsHarpoonLocker::unlock()
text.resize(GetWindowTextLengthA(active_window));
GetWindowTextA(active_window, text.data(), text.size() + 1);
TRACE_MSG("Restore active window: {}", text);
spdlog::info("Restore active window: {} {}", text, reinterpret_cast<intptr_t>(active_window));
SetForegroundWindow(active_window);
active_window = nullptr;
}
Expand Down
3 changes: 2 additions & 1 deletion ui/app/toolkits/qt/AutoUpdater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ AutoUpdater::init_preferences()
->when(&workrave::updater::Config::proxy_type(),
[](unfold::ProxyType t) { return t == unfold::ProxyType::Custom; }));

context->get_preferences_registry()->add_page("auto-update", N_("Software updates"), "workrave-update-symbolic");
// TODO: image is toolkit specific
context->get_preferences_registry()->add_page("auto-update", N_("Software updates"), "update.svg");
context->get_preferences_registry()->add(auto_update_def);
}

Expand Down
22 changes: 15 additions & 7 deletions ui/app/toolkits/qt/BreakWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ BreakWindow::BreakWindow(std::shared_ptr<IApplicationContext> app, QScreen *scre
void
BreakWindow::init()
{
#if defined(HAVE_WAYLAND)
if (Platform::running_on_wayland())
{
auto wm = std::make_shared<WaylandWindowManager>();
bool success = wm->init();
if (success)
{
window_manager = wm;
}
}
#endif

if (block_mode != BlockMode::Off)
{
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::SplashScreen);
Expand Down Expand Up @@ -306,19 +318,18 @@ BreakWindow::check_skip_postpone_lock(bool &skip_locked, bool &postpone_locked,
{
for (int id = break_id - 1; id >= 0; id--)
{
IBreak::Ptr b = core->get_break(BreakId(id));

auto b = core->get_break(BreakId(id));
bool overdue = b->get_elapsed_time() > b->get_limit();

if (((break_flags & BREAK_FLAGS_USER_INITIATED) == 0) || b->is_max_preludes_reached())
{
if (!GUIConfig::break_ignorable(BreakId(id))())
{
skip_locked = overdue;
postpone_locked = overdue;
}
if (!GUIConfig::break_skippable(BreakId(id))())
{
postpone_locked = overdue;
skip_locked = overdue;
}
if (skip_locked || postpone_locked)
{
Expand Down Expand Up @@ -496,9 +507,6 @@ BreakWindow::stop()
}

hide();
// TODO:
// platform->restore_foreground();
// platform->unlock();
}

void
Expand Down
5 changes: 4 additions & 1 deletion ui/app/toolkits/qt/BreakWindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ private:
void on_postpone_button_clicked();
void on_sysoper_combobox_changed(int index);

std::vector<System::SystemOperation> supported_system_operations;
void append_row_to_sysoper_model(System::SystemOperation::SystemOperationType type);
void get_operation_name_and_icon(System::SystemOperation::SystemOperationType type, QString &name, QString &icon_name);

Expand All @@ -93,12 +92,16 @@ private:
QScreen *screen{nullptr};
Frame *frame{nullptr};
QWidget *gui{nullptr};
std::vector<System::SystemOperation> supported_system_operations;
QWidget *block_window{nullptr};
QProgressBar *progress_bar{nullptr};
QPushButton *postpone_button{nullptr};
QPushButton *skip_button{nullptr};
QComboBox *sysoper_combo{nullptr};
std::shared_ptr<SizeGroup> size_group;
#if defined(HAVE_WAYLAND)
std::shared_ptr<WaylandWindowManager> window_manager;
#endif
};

#endif // BREAKWINDOW_HH
23 changes: 22 additions & 1 deletion ui/app/toolkits/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ target_sources(workrave-toolkit-qt PRIVATE
ToolkitFactory.cc
ToolkitMenu.cc
preferences/GeneralUiPreferencesPanel.cc
preferences/MonitoringPreferencesPanel.cc
preferences/SoundsPreferencesPanel.cc
preferences/TimerBoxPreferencesPanel.cc
preferences/TimerPreferencesPanel.cc
Expand All @@ -36,7 +37,27 @@ target_sources(workrave-toolkit-qt PRIVATE

if (PLATFORM_OS_UNIX)
target_sources(workrave-toolkit-qt PRIVATE ToolkitLinux.cc)
target_include_directories(workrave-toolkit-qt PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/platforms/unix)
if (HAVE_WAYLAND)
qt_generate_wayland_protocol_client_sources(workrave-toolkit-qt FILES
platforms/unix/protocols/wlr-layer-shell-unstable-v1.xml
platforms/unix/protocols/xdg-shell.xml)

target_sources(workrave-toolkit-qt 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-qt PRIVATE platforms/unix/DbusMenu.cc)
endif()

if (HAVE_APPINDICATOR)
target_sources(workrave-toolkit-qt PRIVATE platforms/unix/AppIndicatorMenu.cc)
endif()

target_include_directories(workrave-toolkit-qt PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/platforms/unix ${CMAKE_CURRENT_SOURCE_DIR}/platforms/unix/protocols)
target_include_directories(workrave-toolkit-qt PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/platforms/unix)
endif()

if (PLATFORM_OS_WINDOWS)
Expand Down
3 changes: 2 additions & 1 deletion ui/app/toolkits/qt/DebugDialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
using namespace workrave;
using namespace workrave::utils;

DebugDialog::DebugDialog()
DebugDialog::DebugDialog(std::shared_ptr<IApplicationContext> app)
: app(app)
{
setWindowTitle(tr("Debug Workrave"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
Expand Down
7 changes: 6 additions & 1 deletion ui/app/toolkits/qt/DebugDialog.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
#include <QtGui>
#include <QtWidgets>

#include "ui/IApplicationContext.hh"

class DebugDialog : public QDialog
{
Q_OBJECT

public:
DebugDialog();
explicit DebugDialog(std::shared_ptr<IApplicationContext> app);

private:
std::shared_ptr<IApplicationContext> app;
};

#endif // DEBUGDIALOG_HH
Loading

0 comments on commit b0b83b2

Please sign in to comment.