From 477bc6687a05f2820dcd1b8f2663b4a5537fb3ea Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 7 Apr 2021 06:51:25 +0200 Subject: Matrix: mark window as urgent when being mentioned or receiving an invite --- src/QuickMedia.cpp | 23 +++++++++++++++++++++++ src/plugins/Matrix.cpp | 10 ++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index afd8461..ebbbba8 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -445,6 +445,21 @@ namespace QuickMedia { return body_item; } + void Program::window_set_urgent() { + XWMHints *hints = XGetWMHints(disp, x11_window); + if(!hints) { + fprintf(stderr, "seturgent: unable to get window manager hints\n"); + return; + } + + hints->flags |= XUrgencyHint; + + if(!XSetWMHints(disp, x11_window, hints)) + fprintf(stderr, "seturgent: unable to set urgency hint\n"); + + XFree(hints); + } + int Program::run(int argc, char **argv) { if(argc < 2) { usage(); @@ -616,6 +631,14 @@ namespace QuickMedia { XMapWindow(disp, x11_window); XFlush(disp); + XWMHints* hints = XAllocWMHints(); + if(hints) { + hints->flags = AllHints; + hints->initial_state = NormalState; + XSetWMHints(disp, x11_window, hints); + XFree(hints); + } + window.create(x11_window); resources_root = "/usr/share/quickmedia/"; diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 0c44130..9db9872 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -387,8 +387,10 @@ namespace QuickMedia { body_item->thumbnail_size = sf::Vector2i(32, 32); body_item->set_timestamp(invite.timestamp); invites_page->add_body_item(std::move(body_item)); - if(invite.new_invite) + if(invite.new_invite) { show_notification("QuickMedia matrix - " + invite.room_name, "You were invited to " + invite.room_name + " by " + invited_by_display_name + " (" + invite.invited_by->user_id + ")"); + program->window_set_urgent(); + } } void MatrixQuickMedia::remove_invite(const std::string &room_id) { @@ -450,6 +452,8 @@ namespace QuickMedia { show_notification("QuickMedia matrix - " + unread_notification.sender + " (" + it.first->get_name() + ")", unread_notification.body); } } + if(!unread_notifications.empty()) + program->window_set_urgent(); //if(!unread_notifications.empty()) { // rooms_page->sort_rooms(); // room_tags_page->sort_rooms(); @@ -579,8 +583,10 @@ namespace QuickMedia { for(auto &message : messages) { if(message->notification_mentions_me) { // TODO: What if the message or username begins with "-"? also make the notification image be the avatar of the user - if((!is_window_focused || room != current_room || page_type == MatrixPageType::ROOM_LIST) && message->related_event_type != RelatedEventType::EDIT && message->related_event_type != RelatedEventType::REDACTION) + if((!is_window_focused || room != current_room || page_type == MatrixPageType::ROOM_LIST) && message->related_event_type != RelatedEventType::EDIT && message->related_event_type != RelatedEventType::REDACTION) { show_notification("QuickMedia matrix - " + matrix->message_get_author_displayname(message.get()) + " (" + room->get_name() + ")", message->body); + program->window_set_urgent(); + } } } } -- cgit v1.2.3