From 52f8dc5d05f5e34b0a3cf4bb4e4fe607f06965c5 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 14 Jun 2025 21:51:42 +0200 Subject: Better G key behavior in matrix, add ctrl+g for encrypt reply, load mpris from system path if available for videos --- README.md | 3 ++- include/Entry.hpp | 1 + include/Text.hpp | 1 + src/Entry.cpp | 4 ++++ src/QuickMedia.cpp | 45 ++++++++++++++++++++++++++++++++++----------- src/Text.cpp | 4 ++++ src/VideoPlayer.cpp | 32 ++++++++++++++++++++++++-------- 7 files changed, 70 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index e5b6a4d..698750f 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,8 @@ Type text and then wait and QuickMedia will automatically search.\ `Ctrl+P`: Pin the selected message.\ `Ctrl+R`: Navigate to the replied to message.\ `Ctrl+B`: Navigate to the bottom (the latest message).\ -`G`: Start typing an `/encrypt` message, `Esc` to cancel. +`G`: Start typing an `/encrypt` message, `Esc` to cancel.\ +`Ctrl+G`: Start replying to the selected message with `/encrypt`, `Esc` to cancel. #### Pinned messages page controls `Ctrl+D`: Unpin the selected message.\ `Ctrl+R`: Navigate to the pinned message in the messages tab. diff --git a/include/Entry.hpp b/include/Entry.hpp index f4cbc5d..54a5713 100644 --- a/include/Entry.hpp +++ b/include/Entry.hpp @@ -32,6 +32,7 @@ namespace QuickMedia { void replace(size_t start_index, size_t length, const std::string &insert_str); int get_caret_index() const; + void set_caret_index(int index); bool is_editable() const; float get_height(); diff --git a/include/Text.hpp b/include/Text.hpp index 89aba99..21b6dc0 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -117,6 +117,7 @@ namespace QuickMedia void replace(size_t start_index, size_t length, const std::string &insert_str); int getCaretIndex() const; + void setCaretIndex(int index); int getNumLines() const; void set_color(mgl::Color color, bool force_color = false); diff --git a/src/Entry.cpp b/src/Entry.cpp index 5416724..8aa2bba 100644 --- a/src/Entry.cpp +++ b/src/Entry.cpp @@ -107,6 +107,10 @@ namespace QuickMedia { return text.getCaretIndex(); } + void Entry::set_caret_index(int index) { + text.setCaretIndex(index); + } + void Entry::set_position(const mgl::vec2f &pos) { background.set_position(pos); text.set_position(pos + mgl::vec2f(background_margin_horizontal * padding_scale, background_margin_vertical * padding_scale - (float)text.get_character_size() * 0.3f).floor()); diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 8cdc874..3f59c14 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -7162,6 +7162,19 @@ namespace QuickMedia { chat_state = ChatState::TYPING_MESSAGE; }; + auto start_replying = [&](std::shared_ptr selected_body_item) { + RoomExtraData &room_extra_data = matrix->get_room_extra_data(current_room); + chat_state = ChatState::REPLYING; + currently_operating_on_item = selected_body_item; + chat_input.set_editable(true); + if(get_config().matrix.clear_message_on_escape || !room_extra_data.editing_message_id.empty()) { + chat_input.set_text(""); + room_extra_data.editing_message_id.clear(); + } + replying_to_text.set_string("Replying to:"); + frame_skip_text_entry = true; + }; + for(size_t i = 0; i < tabs.size(); ++i) { tabs[i].body->on_top_reached = on_top_reached; tabs[i].body->on_bottom_reached = on_bottom_reached; @@ -7313,7 +7326,11 @@ namespace QuickMedia { if(event.key.code == mgl::Keyboard::G && !event.key.control) { start_typing(); - chat_input.set_text("/encrypt "); + std::string chat_text = chat_input.get_text(); + if(!string_starts_with(chat_text, "/encrypt")) { + chat_input.set_text("/encrypt " + chat_text); + chat_input.set_caret_index(chat_input.get_caret_index() + 9); + } } if(event.key.control && event.key.code == mgl::Keyboard::V) { @@ -7400,21 +7417,27 @@ namespace QuickMedia { // TODO: Show inline notification show_notification("QuickMedia", "You can't reply to a message that hasn't been sent yet"); } else { - RoomExtraData &room_extra_data = matrix->get_room_extra_data(current_room); - chat_state = ChatState::REPLYING; - currently_operating_on_item = selected; - chat_input.set_editable(true); - if(get_config().matrix.clear_message_on_escape || !room_extra_data.editing_message_id.empty()) { - chat_input.set_text(""); - room_extra_data.editing_message_id.clear(); - } - replying_to_text.set_string("Replying to:"); - frame_skip_text_entry = true; + start_replying(std::move(selected)); } } } } + if(event.key.code == mgl::Keyboard::G && event.key.control) { + std::shared_ptr selected = tabs[selected_tab].body->get_selected_shared(); + if(static_cast(selected->userdata)->event_id.empty()) { + // TODO: Show inline notification + show_notification("QuickMedia", "You can't reply to a message that hasn't been sent yet"); + } else { + start_replying(std::move(selected)); + std::string chat_text = chat_input.get_text(); + if(!string_starts_with(chat_text, "/encrypt")) { + chat_input.set_text("/encrypt " + chat_text); + chat_input.set_caret_index(chat_input.get_caret_index() + 9); + } + } + } + if(event.key.code == mgl::Keyboard::B && event.key.control) { // Reload room, goes to latest message l0l move_room = true; diff --git a/src/Text.cpp b/src/Text.cpp index 2b62798..6333e8e 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -285,6 +285,10 @@ namespace QuickMedia int Text::getCaretIndex() const { return caretIndex; } + + void Text::setCaretIndex(int index) { + caretIndex = index; + } void Text::set_color(mgl::Color color, bool force_color) { diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index da92bf7..ea18289 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -177,7 +177,6 @@ namespace QuickMedia { const std::string config_dir = "--config-dir=" + startup_args.resource_root + "mpv"; const std::string input_conf_file = "--input-conf=" + startup_args.resource_root + "mpv/input.conf"; - const std::string ytdl_hook_file = "--scripts=" + startup_args.resource_root + "mpv/scripts/ytdl_hook.lua"; std::vector args; // TODO: Resume playback if the last video played matches the first video played next time QuickMedia is launched @@ -251,18 +250,33 @@ namespace QuickMedia { if(!startup_args.referer.empty()) args.push_back(referer_arg.c_str()); - std::string mpris_arg; - Path mpris_path = get_config_dir_xdg().join("mpv").join("scripts").join("mpris.so"); - if(get_file_type(mpris_path) == FileType::REGULAR) - mpris_arg = "--scripts=" + mpris_path.data; + std::string scripts; + std::string scripts_arg; + + const Path mpris_path = get_config_dir_xdg().join("mpv").join("scripts").join("mpris.so"); + if(get_file_type(mpris_path) == FileType::REGULAR) { + if(!scripts.empty()) + scripts += ":"; + scripts += mpris_path.data; + } + + const Path mpris_system_path = "/etc/mpv/scripts/mpris.so"; + if(get_file_type(mpris_system_path) == FileType::REGULAR) { + if(!scripts.empty()) + scripts += ":"; + scripts += mpris_system_path.data; + } std::string profile_arg; if(startup_args.use_system_mpv_config) { + if(!scripts.empty()) + scripts += ":"; + scripts += startup_args.resource_root + "mpv/scripts/ytdl_hook.lua"; + args.push_back("--config=yes"); args.push_back("--load-scripts=yes"); args.push_back("--osc=yes"); args.push_back(input_conf_file.c_str()); - args.push_back(ytdl_hook_file.c_str()); if(!startup_args.system_mpv_profile.empty()) profile_arg = "--profile=" + startup_args.system_mpv_profile; @@ -271,9 +285,11 @@ namespace QuickMedia { config_dir.c_str(), "--config=yes" }); + } - if(!mpris_arg.empty()) - args.push_back(mpris_arg.c_str()); + if(!scripts.empty()) { + scripts_arg = "--scripts=" + scripts; + args.push_back(scripts_arg.c_str()); } if(!profile_arg.empty()) -- cgit v1.2.3-70-g09d2