Skip to content
This repository was archived by the owner on May 2, 2022. It is now read-only.

Drive trays message queue from existing main loop. #6

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.14)
project(tray VERSION 0.2 DESCRIPTION "A cross-platform C++ system tray library")

file(GLOB src
Expand All @@ -12,7 +12,7 @@ add_library(tray STATIC ${src})
if (UNIX)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
pkg_check_modules(APPINDICATOR REQUIRED appindicator3-0.1)
pkg_check_modules(APPINDICATOR REQUIRED ayatana-appindicator3-0.1)

target_link_libraries(tray INTERFACE ${GTK3_LIBRARIES} ${APPINDICATOR_LIBRARIES})
target_compile_options(tray PRIVATE -Wall -Wextra -Werror -pedantic -Wno-unused-lambda-capture)
Expand All @@ -28,4 +28,4 @@ set_target_properties(tray PROPERTIES
CXX_STANDARD_REQUIRED ON)

set_target_properties(tray PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(tray PROPERTIES PROJECT_NAME ${PROJECT_NAME})
set_target_properties(tray PROPERTIES PROJECT_NAME ${PROJECT_NAME})
5 changes: 3 additions & 2 deletions tray/include/core/linux/tray.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#if defined(__linux__)
#include <core/traybase.hpp>
#include <libappindicator/app-indicator.h>
#include <libayatana-appindicator/app-indicator.h>

namespace Tray
{
Expand All @@ -22,6 +22,7 @@ namespace Tray
void run() override;
void exit() override;
void update() override;
void pump() override;
};
} // namespace Tray
#endif
#endif
1 change: 1 addition & 0 deletions tray/include/core/traybase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Tray
virtual void run() = 0;
virtual void exit() = 0;
virtual void update() = 0;
virtual void pump() = 0;
std::vector<std::shared_ptr<TrayEntry>> getEntries();
};
} // namespace Tray
1 change: 1 addition & 0 deletions tray/include/core/windows/tray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace Tray
void run() override;
void exit() override;
void update() override;
void pump() override;
};
} // namespace Tray
#endif
23 changes: 21 additions & 2 deletions tray/src/core/linux/tray.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if defined(__linux__)
#include <core/linux/tray.hpp>
#include <libappindicator/app-indicator.h>
#include <libayatana-appindicator/app-indicator.h>
#include <stdexcept>

#include <components/button.hpp>
Expand All @@ -20,6 +20,20 @@ Tray::Tray::Tray(std::string identifier, Icon icon) : BaseTray(std::move(identif
}

appIndicator = app_indicator_new(this->identifier.c_str(), this->icon, APP_INDICATOR_CATEGORY_APPLICATION_STATUS);

#if 0
gchar *current_dir = g_get_current_dir();
g_print("%s current_dir:%s\n", G_STRFUNC, current_dir);
gchar *theme_path = g_build_path(G_DIR_SEPARATOR_S,
current_dir,
"data",
NULL);
g_print("%s path:%s\n", G_STRFUNC, theme_path);
app_indicator_set_icon_theme_path(appIndicator, theme_path);
g_free(current_dir);
g_free(theme_path);
#endif

app_indicator_set_status(appIndicator, APP_INDICATOR_STATUS_ACTIVE);
}

Expand Down Expand Up @@ -168,4 +182,9 @@ void Tray::Tray::run()
}
}

#endif
void Tray::Tray::pump()
{
gtk_main_iteration_do(false);
}

#endif
10 changes: 10 additions & 0 deletions tray/src/core/windows/tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,14 @@ void Tray::Tray::run()
}
}

void Tray::Tray::pump()
{
static MSG msg;
if(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

#endif