Skip to content
Merged
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ if(NATIVEAPI_BUILD_EXAMPLES)
add_subdirectory(examples/window_lifecycle_example)
add_subdirectory(examples/window_parent_example)
add_subdirectory(examples/window_shadow_example)
add_subdirectory(examples/window_taskbar_example)
add_subdirectory(examples/window_visual_effect_example)
add_subdirectory(examples/drag_drop_example)
add_subdirectory(examples/desktop_features_example)
Expand Down
24 changes: 24 additions & 0 deletions examples/window_taskbar_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.16)
project(window_taskbar_example)

set(CMAKE_CXX_STANDARD 17)

include_directories(${CMAKE_SOURCE_DIR}/../../include)

add_executable(window_taskbar_example main.cpp)
target_link_libraries(window_taskbar_example nativeapi)

if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
elseif(APPLE)
find_library(COCOA_LIBRARY Cocoa)
target_link_libraries(window_taskbar_example ${COCOA_LIBRARY})
elseif(WIN32)
target_link_libraries(window_taskbar_example user32 kernel32)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
target_include_directories(window_taskbar_example PRIVATE ${GTK3_INCLUDE_DIRS})
target_link_libraries(window_taskbar_example ${GTK3_LIBRARIES})
elseif(ANDROID)
target_link_libraries(window_taskbar_example log android)
endif()
230 changes: 230 additions & 0 deletions examples/window_taskbar_example/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
// WindowTaskbar example: interactive control panel exercising progress states,
// overlay icon, thumbnail toolbar buttons (with live updates, click events, and
// hide/restore recovery), and taskbar flashing.

#include <chrono>
#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <utility>

#include "nativeapi.h"

using namespace nativeapi;

namespace {

constexpr const char* kBadgePng =
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAOUlEQVR42mNgoAV4amn6HxsmWyNRBhGrGachFBmATQE6wG"
"sIIc24DBnOBpAciAOfDqiSlKmSmcgBAELbsdgN1EiUAAAAAElFTkSuQmCC";
constexpr const char* kPlayPng =
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAL0lEQVR42mNgGIZgWsd/MKbYALINQTaALIOwGUCSIbgMIN"
"ogmhkwMIE4MAlpyAEAncFlcf6T6RQAAAAASUVORK5CYII=";
constexpr const char* kPausePng =
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAHUlEQVR42mNgGF7g/wyG/8iYkPioAaMG0MaAoQkAa2zO4f"
"8w4zgAAAAASUVORK5CYII=";
constexpr const char* kPrevPng =
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAN0lEQVR42mNgGD5Acdrn/zBMjFqyDcCphpAByPIkG4CumW"
"gDsGmkrwEUe4FqgUiVaCSYkIYuAAA5K7Tl/slM+AAAAABJRU5ErkJggg==";
constexpr const char* kNextPng =
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAMklEQVR42mNgGD5Acdrn/8SogWGckhQbgM8gkgzApohkA9"
"AV09+AgQlEiqKRooQ0dAEADpu05f0DPosAAAAASUVORK5CYII=";

std::shared_ptr<View> MakeRow() {
auto row = std::make_shared<View>();
row->SetLayout(ViewLayout::Row);
row->SetSpacing(8);
row->SetPreferredSize(Size{0, 32});
return row;
}

std::shared_ptr<Button> AddButton(const std::shared_ptr<View>& row, const std::string& label,
std::function<void()> on_click) {
auto btn = std::make_shared<Button>(label);
btn->SetFlex(1);
btn->AddListener<ButtonClickedEvent>(
[cb = std::move(on_click)](const ButtonClickedEvent&) { cb(); });
row->AddSubview(btn);
return btn;
}

} // namespace

int main() {
auto& app = Application::GetInstance();

auto window = std::make_shared<Window>();
window->SetTitle("WindowTaskbar Example");
window->SetContentSize(Size{620, 370});
window->SetMinimumSize(Size{540, 340});
window->Center();

auto taskbar = window->GetTaskbar();
auto root = window->GetContentView();
if (!root || !taskbar) {
std::cerr << "Failed to initialize content view or WindowTaskbar." << std::endl;
return 1;
}

root->SetLayout(ViewLayout::Column);
root->SetPadding(EdgeInsets::All(16));
root->SetSpacing(10);

auto heading = std::make_shared<Label>("Windows Taskbar API Demo");
heading->SetFontSize(18);
root->AddSubview(heading);

auto status = std::make_shared<Label>(
std::string("WindowTaskbar::IsSupported() = ") +
(WindowTaskbar::IsSupported() ? "true" : "false") +
" | Max buttons = " + std::to_string(WindowTaskbar::GetMaxThumbnailButtonCount()));
status->SetTextColor(Color::FromRGBA(90, 90, 90));
root->AddSubview(status);

auto set_status = [status](const std::string& text) {
status->SetText(text);
std::cout << "[taskbar] " << text << std::endl;
};

auto badge_icon = Image::FromBase64(kBadgePng);
auto play_icon = Image::FromBase64(kPlayPng);
auto pause_icon = Image::FromBase64(kPausePng);
auto prev_icon = Image::FromBase64(kPrevPng);
auto next_icon = Image::FromBase64(kNextPng);

// --- Section 1: Progress ---
auto progress_label = std::make_shared<Label>("1. Progress Indicator");
root->AddSubview(progress_label);
auto progress_row = MakeRow();
AddButton(progress_row, "Normal 35%", [=] {
bool ok = taskbar->SetProgressState(TaskbarProgressState::Normal) &&
taskbar->SetProgressValue(0.35);
set_status(ok ? "Progress: Normal 35%" : "SetProgress failed");
});
AddButton(progress_row, "75%", [=] {
bool ok = taskbar->SetProgressValue(0.75);
set_status(ok ? "Progress: 75% (preserves active state)" : "SetProgressValue failed");
});
AddButton(progress_row, "Paused", [=] {
bool ok = taskbar->SetProgressState(TaskbarProgressState::Paused);
set_status(ok ? "Progress: Paused" : "SetProgressState(Paused) failed");
});
AddButton(progress_row, "Error", [=] {
bool ok = taskbar->SetProgressState(TaskbarProgressState::Error);
set_status(ok ? "Progress: Error" : "SetProgressState(Error) failed");
});
AddButton(progress_row, "Busy", [=] {
bool ok = taskbar->SetProgressState(TaskbarProgressState::Indeterminate);
set_status(ok ? "Progress: Indeterminate" : "SetProgressState(Indeterminate) failed");
});
AddButton(progress_row, "Clear", [=] {
bool ok = taskbar->SetProgressState(TaskbarProgressState::None);
set_status(ok ? "Progress: Cleared" : "SetProgressState(None) failed");
});
root->AddSubview(progress_row);

// --- Section 2: Overlay Icon ---
auto overlay_label = std::make_shared<Label>("2. Overlay Icon");
root->AddSubview(overlay_label);
auto overlay_row = MakeRow();
AddButton(overlay_row, "Set Overlay Icon", [=] {
bool ok = taskbar->SetOverlayIcon(badge_icon, "Unread notification");
set_status(ok ? "Overlay icon set" : "SetOverlayIcon failed");
});
AddButton(overlay_row, "Clear Overlay Icon", [=] {
bool ok = taskbar->SetOverlayIcon(nullptr);
set_status(ok ? "Overlay icon cleared" : "Clear overlay failed");
});
AddButton(overlay_row, "Hide & Restore (1.5s)", [=] {
set_status("Hiding window for 1.5s to verify taskbar recovery...");
window->Hide();
std::thread([window, set_status] {
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
RunOnMainThread([window, set_status] {
window->Show();
set_status("Window restored (check overlay, progress, and toolbar buttons)");
});
}).detach();
});
root->AddSubview(overlay_row);

// --- Section 3: Thumbnail Toolbar ---
auto toolbar_label =
std::make_shared<Label>("3. Thumbnail Toolbar (hover taskbar icon to click media buttons)");
root->AddSubview(toolbar_label);

auto playing = std::make_shared<bool>(false);
auto prev_btn = std::make_shared<TaskbarThumbnailButton>(prev_icon, "Previous Track");
auto play_btn = std::make_shared<TaskbarThumbnailButton>(play_icon, "Play");
auto next_btn = std::make_shared<TaskbarThumbnailButton>(next_icon, "Next Track");

auto toggle_play = [=] {
*playing = !*playing;
play_btn->SetIcon(*playing ? pause_icon : play_icon);
play_btn->SetTooltip(*playing ? "Pause" : "Play");
set_status(*playing ? "Playback: Playing (thumbnail icon updated live)"
: "Playback: Paused (thumbnail icon updated live)");
};

prev_btn->AddListener<TaskbarThumbnailButtonClickedEvent>(
[=](const TaskbarThumbnailButtonClickedEvent& e) {
set_status("Thumbnail button clicked: Previous (id=" + std::to_string(e.GetButtonId()) +
")");
});
play_btn->AddListener<TaskbarThumbnailButtonClickedEvent>(
[=](const TaskbarThumbnailButtonClickedEvent&) { toggle_play(); });
next_btn->AddListener<TaskbarThumbnailButtonClickedEvent>(
[=](const TaskbarThumbnailButtonClickedEvent& e) {
set_status("Thumbnail button clicked: Next (id=" + std::to_string(e.GetButtonId()) + ")");
});

auto toolbar_row = MakeRow();
AddButton(toolbar_row, "Setup 3 Buttons", [=] {
taskbar->ClearThumbnailButtons();
bool ok = taskbar->AddThumbnailButton(prev_btn) && taskbar->AddThumbnailButton(play_btn) &&
taskbar->AddThumbnailButton(next_btn);
set_status(ok ? "Added 3 thumbnail toolbar buttons (hover taskbar icon)"
: "AddThumbnailButton failed");
});
AddButton(toolbar_row, "Toggle Play/Pause", [=] { toggle_play(); });
AddButton(toolbar_row, "Toggle Prev Enabled", [=] {
prev_btn->SetEnabled(!prev_btn->IsEnabled());
set_status(prev_btn->IsEnabled() ? "Previous button: Enabled" : "Previous button: Disabled");
});
AddButton(toolbar_row, "Clear Toolbar", [=] {
taskbar->ClearThumbnailButtons();
set_status("Thumbnail toolbar cleared");
});
root->AddSubview(toolbar_row);

// --- Section 4: Flashing ---
auto flash_label = std::make_shared<Label>("4. Attention / Flashing");
root->AddSubview(flash_label);
auto flash_row = MakeRow();
AddButton(flash_row, "Flash 5x", [=] {
TaskbarFlashOptions opts{};
opts.target = TaskbarFlashTarget::All;
opts.count = 5;
opts.timeout_ms = 250;
opts.stop_on_foreground = false;
bool ok = taskbar->StartFlashing(opts);
set_status(ok ? "Flashing 5 times (250ms)" : "StartFlashing failed");
});
AddButton(flash_row, "Flash Continuous", [=] {
TaskbarFlashOptions opts{};
opts.target = TaskbarFlashTarget::Taskbar;
opts.count = 0;
opts.timeout_ms = 0;
opts.stop_on_foreground = false;
bool ok = taskbar->StartFlashing(opts);
set_status(ok ? "Flashing taskbar continuously (click Stop Flash)" : "StartFlashing failed");
});
AddButton(flash_row, "Stop Flash", [=] {
bool ok = taskbar->StopFlashing();
set_status(ok ? "Stopped flashing" : "StopFlashing failed");
});
root->AddSubview(flash_row);

return app.Run(window);
}
2 changes: 2 additions & 0 deletions include/nativeapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "../src/window_manager.h"
#include "../src/window_shadow.h"
#include "../src/window_shape.h"
#include "../src/window_taskbar.h"
#endif

// C API (usable from both C and C++)
Expand Down Expand Up @@ -84,3 +85,4 @@
#include "../src/capi/window_manager_c.h"
#include "../src/capi/window_shadow_c.h"
#include "../src/capi/window_shape_c.h"
#include "../src/capi/window_taskbar_c.h"
15 changes: 15 additions & 0 deletions src/capi/window_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "window_shadow_c.h"
#include "../view.h"
#include "view_c.h"
#include "../window_taskbar.h"
#include "window_taskbar_c.h"
#include "../window.h"

native_window_t native_window_create(void) {
Expand Down Expand Up @@ -1567,6 +1569,19 @@ bool native_window_is_visible_in_taskbar(native_window_t window) {
}
}

native_window_taskbar_t native_window_get_taskbar(native_window_t window) {
auto self = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::Window>(window);
if (!self) {
return 0;
}
try {
return nativeapi::HandleTable::GetInstance().Insert(self->GetTaskbar());
} catch (...) {
fprintf(stderr, "[nativeapi] %s: unexpected exception\n", "native_window_get_taskbar");
return 0;
}
}

bool native_window_set_ignore_mouse_events(native_window_t window, bool is_ignore_mouse_events, bool forward) {
auto self = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::Window>(window);
if (!self) {
Expand Down
6 changes: 6 additions & 0 deletions src/capi/window_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ typedef uint64_t native_event_request_t;
typedef uint64_t native_view_t;
typedef uint64_t native_window_shadow_t;
typedef uint64_t native_window_shape_t;
typedef uint64_t native_window_taskbar_t;

#include "color_c.h"
#include "event_request_c.h"
#include "geometry_c.h"
#include "view_c.h"
#include "window_shadow_c.h"
#include "window_shape_c.h"
#include "window_taskbar_c.h"

#if _WIN32
#define FFI_PLUGIN_EXPORT __declspec(dllexport)
Expand Down Expand Up @@ -526,6 +528,10 @@ void native_window_set_visible_in_taskbar(native_window_t window, bool is_visibl
FFI_PLUGIN_EXPORT
bool native_window_is_visible_in_taskbar(native_window_t window);

/// Caller owns the returned handle; release it with native_window_taskbar_free().
FFI_PLUGIN_EXPORT
native_window_taskbar_t native_window_get_taskbar(native_window_t window);

FFI_PLUGIN_EXPORT
bool native_window_set_ignore_mouse_events(native_window_t window, bool is_ignore_mouse_events, bool forward);

Expand Down
Loading
Loading