Compare commits
3 Commits
Prerelease
...
main
Author | SHA1 | Date | |
---|---|---|---|
f979e5738f | |||
2291ee6215 | |||
edcd5a7fca |
@@ -46,14 +46,17 @@ file(GLOB_RECURSE HEADERS "include/logger/*.h" "include/logger/*.hpp")
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
file(GLOB_RECURSE SOURCES "src/types/*.cpp" "src/platform/linux/*.cpp" "src/platform/shared/*.cpp" "src/ReWindow/*.cpp" )
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(DBUS REQUIRED dbus-1)
|
||||
include_directories("include" ${DBUS_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
file(GLOB_RECURSE SOURCES "src/types/*.cpp" "src/platform/windows/*.cpp" "src/platform/shared/*.cpp" "src/ReWindow/*.cpp")
|
||||
include_directories("include")
|
||||
endif()
|
||||
|
||||
include_directories("include")
|
||||
|
||||
if(UNIX)
|
||||
add_library(ReWindow SHARED ${SOURCES})
|
||||
endif()
|
||||
@@ -68,7 +71,7 @@ target_include_directories(ReWindow PUBLIC ${Event_SOURCE_DIR}/include)
|
||||
set_target_properties(ReWindow PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_link_libraries(ReWindow PUBLIC X11 Event jlog)
|
||||
target_link_libraries(ReWindow PUBLIC X11 Event jlog ${DBUS_LIBRARIES})
|
||||
target_link_libraries(ReWindow PUBLIC)
|
||||
add_executable(ReWindowDemo main.cpp)
|
||||
target_link_libraries(ReWindowDemo PUBLIC ReWindow)
|
||||
|
@@ -25,8 +25,8 @@ A library which allows easily creating and managing a window and it's events acr
|
||||
Install dependencies
|
||||
|
||||
```bash
|
||||
Fedora/RHEL: dnf install cmake make gcc-g++ libX11 libX11-devel mesa-libGL-devel vulkan-loader-devel
|
||||
Ubuntu/Debian: apt-get install cmake make gcc g++ libx11-6 libx11-dev libgl-dev libvulkan-dev libxrandr-dev
|
||||
Fedora/RHEL: dnf install cmake make gcc-g++ libX11 libX11-devel mesa-libGL-devel vulkan-loader-devel dbus-devel
|
||||
Ubuntu/Debian: apt-get install cmake make gcc g++ libx11-6 libx11-dev libgl-dev libvulkan-dev libxrandr-dev libdbus-1-dev
|
||||
```
|
||||
|
||||
Clone the repository
|
||||
|
@@ -35,6 +35,9 @@ namespace MouseButtons
|
||||
static const MouseButton Mouse5 ("5", 9);
|
||||
static const MouseButton Unimplemented ("?", 0);
|
||||
|
||||
static const MouseButton PinchIn ("+", 6);
|
||||
static const MouseButton PinchOut("-", 7);
|
||||
|
||||
/// NOTE: IsMouseButtonDown will not return correctly for the mouse-wheel-buttons, because the action is effectively instantaneous.
|
||||
static const MouseButton MWheelUp ("U", 4);
|
||||
/// NOTE: IsMouseButtonDown will not return correctly for the mouse-wheel-buttons, because the action is effectively instantaneous.
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <map>
|
||||
#include <filesystem>
|
||||
#include <Event.h>
|
||||
#include <ReWindow/types/Key.h>
|
||||
#include <ReWindow/types/Cursors.h>
|
||||
@@ -371,6 +372,13 @@ public:
|
||||
/// @note If the window is already in focus when this is called nothing happens.
|
||||
void Flash();
|
||||
|
||||
/// Sends a notification to the operating system notification area.
|
||||
/// @param title The notification title.
|
||||
/// @param content The actual text of the notification.
|
||||
/// @param icon The path to the icon to be displayed on the notification, Empty for none.
|
||||
/// @note On Windows, icon must be a .ico
|
||||
bool Notify(const std::string& title, const std::string& content, const std::filesystem::path& icon = "");
|
||||
|
||||
/// @returns True if we are definitely running on a software renderer.
|
||||
/// @note For some APIs this isn't typically possible.
|
||||
[[nodiscard]] virtual bool SoftwareRendered() { return false; }
|
||||
|
1
main.cpp
1
main.cpp
@@ -48,6 +48,7 @@ int main() {
|
||||
auto* window = new MyWindow("Test Window", 600, 480);
|
||||
Logger::Debug(std::format("New window '{}' created. width={} height={}", window->GetTitle(), window->GetWidth(), window->GetHeight()));
|
||||
|
||||
window->Notify("Hello", "Test notification.");
|
||||
if (window->Open())
|
||||
Logger::Debug(std::format("Opened window '{}'", window->GetTitle()));
|
||||
|
||||
|
@@ -1 +1 @@
|
||||
Main:new("Install build dependencies", "apt-get install -yq libx11-6 libx11-dev libgl-dev libvulkan-dev")
|
||||
Main:new("Install build dependencies", "apt-get install -yq libx11-6 libx11-dev libgl-dev libvulkan-dev libdbus-1-dev")
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
#include <ReWindow/types/Window.h>
|
||||
#include <ReWindow/types/Cursors.h>
|
||||
#include <ReWindow/Logger.h>
|
||||
@@ -6,6 +7,7 @@
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <thread>
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
class ReWindow::RWindow::Platform {
|
||||
public:
|
||||
@@ -30,6 +32,65 @@ public:
|
||||
|
||||
using namespace ReWindow;
|
||||
|
||||
bool RWindow::Notify(const std::string& title, const std::string& content, const std::filesystem::path& icon) {
|
||||
DBusError db_error;
|
||||
dbus_error_init(&db_error);
|
||||
|
||||
DBusConnection* db_connection = dbus_bus_get(DBUS_BUS_SESSION, &db_error);
|
||||
|
||||
if (!db_connection) {
|
||||
dbus_error_free(&db_error);
|
||||
return false;
|
||||
}
|
||||
|
||||
DBusMessage* db_message = dbus_message_new_method_call(
|
||||
"org.freedesktop.Notifications",
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications",
|
||||
"Notify"
|
||||
);
|
||||
|
||||
if (!db_message)
|
||||
return false;
|
||||
|
||||
const char* sender = this->title.c_str();
|
||||
uint32_t replaces_id = 0;
|
||||
const char* app_icon = icon.c_str();
|
||||
const char* summary = title.c_str();
|
||||
const char* body = content.c_str();
|
||||
const char** actions = nullptr;
|
||||
|
||||
DBusMessageIter db_args;
|
||||
dbus_message_iter_init_append(db_message, &db_args);
|
||||
|
||||
dbus_message_iter_append_basic(&db_args, DBUS_TYPE_STRING, &sender);
|
||||
dbus_message_iter_append_basic(&db_args, DBUS_TYPE_UINT32, &replaces_id);
|
||||
dbus_message_iter_append_basic(&db_args, DBUS_TYPE_STRING, &app_icon);
|
||||
dbus_message_iter_append_basic(&db_args, DBUS_TYPE_STRING, &summary);
|
||||
dbus_message_iter_append_basic(&db_args, DBUS_TYPE_STRING, &body);
|
||||
|
||||
DBusMessageIter db_actions_array_iterator;
|
||||
dbus_message_iter_open_container(&db_args, DBUS_TYPE_ARRAY, "s", &db_actions_array_iterator);
|
||||
dbus_message_iter_close_container(&db_args, &db_actions_array_iterator);
|
||||
|
||||
dbus_message_iter_open_container(&db_args, DBUS_TYPE_ARRAY, "{sv}", &db_actions_array_iterator);
|
||||
dbus_message_iter_close_container(&db_args, &db_actions_array_iterator);
|
||||
|
||||
int32_t notif_timeout = 5000;
|
||||
dbus_message_iter_append_basic(&db_args, DBUS_TYPE_INT32, ¬if_timeout);
|
||||
|
||||
DBusMessage* db_reply = dbus_connection_send_with_reply_and_block(db_connection, db_message, -1, &db_error);
|
||||
dbus_message_unref(db_message);
|
||||
|
||||
if (!db_reply) {
|
||||
dbus_error_free(&db_error);
|
||||
return false;
|
||||
}
|
||||
|
||||
dbus_message_unref(db_reply);
|
||||
return true;
|
||||
}
|
||||
|
||||
void RWindow::SetSize(const std::pair<int, int>& size) {
|
||||
this->SetSize(size.first, size.second);
|
||||
}
|
||||
|
@@ -16,6 +16,42 @@ public:
|
||||
|
||||
using namespace ReWindow;
|
||||
|
||||
// TODO destroy n_data after it's no longer shown. Destroying it early causes the notification to come from explorer.
|
||||
bool RWindow::Notify(const std::string& title, const std::string& content, const std::filesystem::path& icon) {
|
||||
NOTIFYICONDATA n_data = {};
|
||||
HICON n_icon = nullptr;
|
||||
|
||||
if (!icon.empty()) {
|
||||
n_icon = (HICON) LoadImageW(
|
||||
nullptr,
|
||||
icon.c_str(),
|
||||
IMAGE_ICON,
|
||||
0, 0,
|
||||
LR_LOADFROMFILE | LR_DEFAULTSIZE
|
||||
);
|
||||
|
||||
if (!n_icon)
|
||||
return false;
|
||||
}
|
||||
|
||||
n_data.cbSize = sizeof(NOTIFYICONDATA);
|
||||
n_data.hWnd = platform->hwnd;
|
||||
n_data.uID = 1;
|
||||
n_data.uFlags = NIF_INFO | NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
||||
n_data.uCallbackMessage = WM_USER + 1;
|
||||
n_data.hIcon = n_icon;
|
||||
lstrcpy(n_data.szTip, title.c_str());
|
||||
lstrcpy(n_data.szInfo, content.c_str());
|
||||
lstrcpy(n_data.szInfoTitle, title.c_str());
|
||||
n_data.dwInfoFlags = NIIF_USER;
|
||||
|
||||
Shell_NotifyIcon(NIM_ADD, &n_data);
|
||||
Shell_NotifyIcon(NIM_MODIFY, &n_data);
|
||||
|
||||
//Shell_NotifyIcon(NIM_DELETE, &n_data);
|
||||
return true;
|
||||
}
|
||||
|
||||
void RWindow::SetSize(int newWidth, int newHeight) {
|
||||
if (!resizable)
|
||||
return;
|
||||
|
@@ -25,6 +25,8 @@ MouseButton GetMouseButtonFromXButton(unsigned int button) {
|
||||
//case 4: return MouseButtons::MWheelUp;
|
||||
//case 5: return MouseButtons::MWheelDown;
|
||||
//For *whatever* reason. These aren't in X.h
|
||||
case 6: return MouseButtons::PinchIn;
|
||||
case 7: return MouseButtons::PinchOut;
|
||||
case 8: return MouseButtons::Mouse4;
|
||||
case 9: return MouseButtons::Mouse5;
|
||||
default: {
|
||||
|
Reference in New Issue
Block a user