diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-10-07 21:14:32 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-10-10 10:16:54 +0200 |
commit | 85a1edf8d9c21b830f7ec4a2d42b8e5c1d044845 (patch) | |
tree | ae52bde5c03546123c0837be7df98fc9a3ea9a00 /src | |
parent | cd94bfc187d6a716f00d218e514409d8e65603c4 (diff) |
Matrix: only show notification on mention if window is not focused or message was received in another room
Also fix caret position in text being incorrect after resize.
Change caret behavior when pressing up/down at the first/last row,
to not go to the beginning/end.
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 17 | ||||
-rw-r--r-- | src/Text.cpp | 8 |
2 files changed, 11 insertions, 14 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index a0e9b78..3922ceb 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3434,8 +3434,12 @@ namespace QuickMedia { }; std::unordered_map<std::string, RoomBodyData> body_items_by_room_id; + std::string current_room_id; + RoomBodyData *current_room_body_data = nullptr; - auto process_new_room_messages = [matrix, &body_items_by_room_id](RoomSyncMessages &room_sync_messages, bool only_show_mentions) mutable { + bool is_window_focused = window.hasFocus(); + + auto process_new_room_messages = [matrix, &body_items_by_room_id, ¤t_room_id, &is_window_focused](RoomSyncMessages &room_sync_messages, bool only_show_mentions) mutable { for(auto &[room, messages] : room_sync_messages) { bool was_mentioned = false; for(auto &message : messages) { @@ -3443,7 +3447,8 @@ namespace QuickMedia { was_mentioned = true; message->mentions_me = false; // TODO: What if the message or username begins with "-"? also make the notification image be the avatar of the user - show_notification("QuickMedia matrix - " + matrix->message_get_author_displayname(message.get()) + " (" + room->name + ")", message->body); + if(!is_window_focused || room->id != current_room_id) + show_notification("QuickMedia matrix - " + matrix->message_get_author_displayname(message.get()) + " (" + room->name + ")", message->body); } } @@ -3481,12 +3486,6 @@ namespace QuickMedia { } }; - // The room id should be saved in a file when changing viewed room. - std::string current_room_id; - RoomBodyData *current_room_body_data = nullptr; - - // get_all_room_messages is not needed here because its done in the loop, where the initial timeout is 0ms - enum class ChatState { NAVIGATING, TYPING_MESSAGE, @@ -3711,8 +3710,6 @@ namespace QuickMedia { return result; }; - bool is_window_focused = true; - while (current_page == Page::CHAT) { sf::Int32 frame_time_ms = frame_timer.restart().asMilliseconds(); while (window.pollEvent(event)) { diff --git a/src/Text.cpp b/src/Text.cpp index d58473d..c1adc5d 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -97,6 +97,7 @@ namespace QuickMedia { this->maxWidth = maxWidth; dirty = true; + dirtyCaret = true; } } @@ -567,7 +568,7 @@ namespace QuickMedia } if(closest_index != -1) return closest_index; - return 0; + return startIndex; } // TODO: This can be optimized by using binary search @@ -588,7 +589,7 @@ namespace QuickMedia } if(closest_index != -1) return closest_index; - return num_vertices; + return startIndex; } // TODO: Optimize text editing by only processing the changed parts in updateGeometry. @@ -697,8 +698,7 @@ namespace QuickMedia { updateGeometry(); - if(dirtyCaret || caretMoveDirection != CaretMoveDirection::NONE) - { + if(editable && (dirtyCaret || caretMoveDirection != CaretMoveDirection::NONE)) { updateCaret(); dirtyCaret = false; caretMoveDirection = CaretMoveDirection::NONE; |