aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp136
1 files changed, 67 insertions, 69 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 42b7106..c9094e3 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -149,6 +149,7 @@ static int get_monitor_max_hz(Display *display) {
static int get_largest_monitor_height(Display *display) {
int max_height = 0;
+
for_each_active_monitor_output(display, [&max_height](const XRRCrtcInfo *crtc_info, const XRRModeInfo*) {
// Need to get the min of width or height because we want to get the smallest size for monitors in portrait mode, for mobile devices such as pinephone
int width_or_height = std::min((int)crtc_info->width, (int)crtc_info->height);
@@ -156,8 +157,9 @@ static int get_largest_monitor_height(Display *display) {
});
if(max_height == 0)
- return DefaultScreenOfDisplay(display)->height;
- return std::max(max_height, 480);
+ max_height = DefaultScreenOfDisplay(display)->height;
+
+ return std::max(max_height, 240);
}
static void get_screen_resolution(Display *display, int *width, int *height) {
@@ -587,8 +589,10 @@ namespace QuickMedia {
void Program::init(Window parent_window, std::string &program_path) {
disp = XOpenDisplay(NULL);
- if (!disp)
- throw std::runtime_error("Failed to open display to X11 server");
+ if (!disp) {
+ fprintf(stderr, "Failed to open display to X11 server\n");
+ abort();
+ }
XSetErrorHandler(x_error_handler);
XSetIOErrorHandler(x_io_error_handler);
@@ -610,8 +614,10 @@ namespace QuickMedia {
InputOutput,
DefaultVisual(disp, screen),
0, nullptr);
- if(!x11_window)
- throw std::runtime_error("Failed to create window");
+ if(!x11_window) {
+ fprintf(stderr, "Failed to create window\n");
+ abort();
+ }
if(strcmp(plugin_name, "download") == 0) {
XSizeHints *size_hints = XAllocSizeHints();
@@ -656,6 +662,11 @@ namespace QuickMedia {
fprintf(stderr, "Failed to load %s/shaders/rounded_rectangle.glsl\n", resources_root.c_str());
abort();
}
+
+ if(!rounded_rectangle_mask_shader.loadFromFile(resources_root + "shaders/rounded_rectangle_mask.glsl", sf::Shader::Type::Fragment)) {
+ fprintf(stderr, "Failed to load %s/shaders/rounded_rectangle_mask.glsl\n", resources_root.c_str());
+ abort();
+ }
}
if(!loading_icon.loadFromFile(resources_root + "images/loading_icon.png")) {
@@ -691,14 +702,20 @@ namespace QuickMedia {
*/
fprintf(stderr, "Monitor hz: %d\n", monitor_hz);
- if(create_directory_recursive(get_cache_dir().join("media")) != 0)
- throw std::runtime_error("Failed to create media directory");
+ if(create_directory_recursive(get_cache_dir().join("media")) != 0) {
+ fprintf(stderr, "Failed to create media directory\n");
+ abort();
+ }
- if(create_directory_recursive(get_cache_dir().join("thumbnails")) != 0)
- throw std::runtime_error("Failed to create thumbnails directory");
+ if(create_directory_recursive(get_cache_dir().join("thumbnails")) != 0) {
+ fprintf(stderr, "Failed to create thumbnails directory\n");
+ abort();
+ }
- //if(create_directory_recursive(get_storage_dir().join("file-manager")) != 0)
- // throw std::runtime_error("Failed to create file-manager directory");
+ //if(create_directory_recursive(get_storage_dir().join("file-manager")) != 0) {
+ // fprintf(stderr, "Failed to create file-manager directory\n");
+ // abort();
+ //}
const char *qm_phone_factor = getenv("QM_PHONE_FACTOR");
if(qm_phone_factor && atoi(qm_phone_factor) == 1)
@@ -1387,13 +1404,7 @@ namespace QuickMedia {
}
static void get_body_dimensions(const sf::Vector2f &window_size, SearchBar *search_bar, sf::Vector2f &body_pos, sf::Vector2f &body_size, bool has_tabs = false) {
- float body_padding_horizontal = 10.0f;
- float body_padding_vertical = std::floor(10.0f);
- float body_width = window_size.x - body_padding_horizontal * 2.0f;
- /*if(body_width <= 480.0f) {
- body_width = window_size.x;
- body_padding_horizontal = 10.0f;
- }*/
+ const float body_width = window_size.x;
float tab_h = Tabs::get_shade_height();
if(!search_bar)
@@ -1403,12 +1414,12 @@ namespace QuickMedia {
tab_h = 0.0f;
float search_bottom = search_bar ? search_bar->getBottomWithoutShadow() : 0.0f;
- body_pos = sf::Vector2f(body_padding_horizontal, search_bottom + body_padding_vertical + tab_h);
- body_size = sf::Vector2f(body_width, window_size.y - search_bottom - body_padding_vertical - tab_h);
+ body_pos = sf::Vector2f(0.0f, search_bottom + tab_h);
+ body_size = sf::Vector2f(body_width, window_size.y - search_bottom - tab_h);
}
- std::unique_ptr<Body> Program::create_body() {
- auto body = std::make_unique<Body>(this, loading_icon, &rounded_rectangle_shader);
+ std::unique_ptr<Body> Program::create_body(bool plain_text_list) {
+ auto body = std::make_unique<Body>(plain_text_list ? BODY_THEME_MINIMAL : BODY_THEME_MODERN_SPACIOUS, loading_icon, &rounded_rectangle_shader, &rounded_rectangle_mask_shader);
body->thumbnail_mask_shader = &circle_mask_shader;
return body;
}
@@ -1748,6 +1759,7 @@ namespace QuickMedia {
current_page = PageType::CHAT;
current_chat_room = matrix->get_room_by_id(tmp_matrix_chat_page->room_id);
+ rooms_page->body->show_drop_shadow = false;
while(window.isOpen() && current_chat_room) {
auto matrix_chat_page = std::make_unique<MatrixChatPage>(this, current_chat_room->id, rooms_page);
bool move_room = chat_page(matrix_chat_page.get(), current_chat_room);
@@ -1761,6 +1773,7 @@ namespace QuickMedia {
current_chat_room = matrix->get_room_by_id(selected_item->url);
}
+ rooms_page->body->show_drop_shadow = true;
room_list_body->body_item_select_callback = [&submit_handler](BodyItem *body_item) {
submit_handler(body_item->get_title());
@@ -2213,7 +2226,7 @@ namespace QuickMedia {
unsigned long num_items = 0;
unsigned long bytes_after = 0;
unsigned char *properties = nullptr;
- if(XGetWindowProperty(display, window, wm_state_atom, 0, 1024, False, XA_ATOM, &type, &format, &num_items, &bytes_after, &properties) != Success) {
+ if(XGetWindowProperty(display, window, wm_state_atom, 0, 1024, False, XA_ATOM, &type, &format, &num_items, &bytes_after, &properties) != Success || !properties) {
fprintf(stderr, "Failed to get window wm state property\n");
return false;
}
@@ -3405,7 +3418,7 @@ namespace QuickMedia {
bool frame_skip_text_entry = false;
comment_input.on_submit_callback = [&frame_skip_text_entry, &comment_input, &post_comment_future, &navigation_stage, &request_new_google_captcha_challenge, &comment_to_post, &captcha_post_id, &captcha_solved_time, &post_comment, &selected_file_for_upload, &thread_page](std::string text) -> bool {
- if(text.empty())
+ if(text.empty() && selected_file_for_upload.empty())
return false;
comment_input.set_editable(false);
@@ -3737,19 +3750,13 @@ namespace QuickMedia {
comment_input.set_max_width(window_size.x - (logo_padding_x + logo_size.x + chat_input_padding_x + logo_padding_x));
comment_input.set_position(sf::Vector2f(std::floor(logo_padding_x + logo_size.x + chat_input_padding_x), chat_input_padding_y));
- float body_padding_horizontal = 10.0f;
- float body_padding_vertical = std::floor(10.0f);
- float body_width = window_size.x - body_padding_horizontal * 2.0f;
- /*if(body_width <= 480.0f) {
- body_width = window_size.x;
- body_padding_horizontal = 0.0f;
- }*/
+ const float body_width = window_size.x;
comment_input_shade.setSize(sf::Vector2f(window_size.x, chat_input_height_full));
comment_input_shade.setPosition(0.0f, 0.0f);
- body_pos = sf::Vector2f(body_padding_horizontal, comment_input_shade.getSize().y + body_padding_vertical);
- body_size = sf::Vector2f(body_width, window_size.y - comment_input_shade.getSize().y - body_padding_vertical);
+ body_pos = sf::Vector2f(0.0f, comment_input_shade.getSize().y);
+ body_size = sf::Vector2f(body_width, window_size.y - comment_input_shade.getSize().y);
logo_sprite.setPosition(logo_padding_x, chat_input_padding_y);
file_to_upload_sprite.setPosition(logo_sprite.getPosition() + sf::Vector2f(0.0f, logo_size.y + logo_file_to_upload_spacing));
@@ -4127,26 +4134,27 @@ namespace QuickMedia {
std::vector<ChatTab> tabs;
ChatTab pinned_tab;
- pinned_tab.body = create_body();
+ pinned_tab.body = create_body(true);
pinned_tab.body->thumbnail_max_size = CHAT_MESSAGE_THUMBNAIL_MAX_SIZE;
pinned_tab.body->attach_side = AttachSide::BOTTOM;
- pinned_tab.body->line_separator_color = sf::Color::Transparent;
tabs.push_back(std::move(pinned_tab));
ChatTab messages_tab;
- messages_tab.body = create_body();
+ messages_tab.body = create_body(true);
messages_tab.body->thumbnail_max_size = CHAT_MESSAGE_THUMBNAIL_MAX_SIZE;
messages_tab.body->attach_side = AttachSide::BOTTOM;
- messages_tab.body->line_separator_color = sf::Color::Transparent;
tabs.push_back(std::move(messages_tab));
ChatTab users_tab;
- users_tab.body = create_body();
+ users_tab.body = create_body(true);
users_tab.body->thumbnail_max_size = CHAT_MESSAGE_THUMBNAIL_MAX_SIZE;
users_tab.body->attach_side = AttachSide::TOP;
- users_tab.body->line_separator_color = sf::Color::Transparent;
tabs.push_back(std::move(users_tab));
+ for(ChatTab &tab : tabs) {
+ tab.body->show_drop_shadow = false;
+ }
+
Tabs ui_tabs(&rounded_rectangle_shader, is_touch_enabled() ? sf::Color::Transparent : back_color);
const int PINNED_TAB_INDEX = ui_tabs.add_tab("Pinned messages (0)");
const int MESSAGES_TAB_INDEX = ui_tabs.add_tab("Messages");
@@ -4168,7 +4176,7 @@ namespace QuickMedia {
bool setting_read_marker = false;
sf::Clock start_typing_timer;
- const double typing_timeout_seconds = 3.0;
+ const double typing_timeout_seconds = 5.0;
bool typing = false;
MessageQueue<bool> typing_state_queue;
@@ -4425,7 +4433,7 @@ namespace QuickMedia {
ui_tabs.set_text(PINNED_TAB_INDEX, "Pinned messages (" + std::to_string(tabs[PINNED_TAB_INDEX].body->items.size()) + ")");
};
- Body url_selection_body(this, loading_icon, &rounded_rectangle_shader);
+ Body url_selection_body(BODY_THEME_MINIMAL, loading_icon, &rounded_rectangle_shader, &rounded_rectangle_mask_shader);
std::unordered_set<std::string> fetched_messages_set;
auto filter_existing_messages = [&fetched_messages_set](Messages &messages) {
@@ -5219,9 +5227,6 @@ namespace QuickMedia {
tabs[i].body->on_top_reached = on_top_reached;
}
- const float body_padding_horizontal = 10.0f;
- const float body_padding_vertical = 10.0f;
-
while (current_page == PageType::CHAT && window.isOpen() && !move_room) {
sf::Int32 frame_time_ms = frame_timer.restart().asMilliseconds();
while (window.pollEvent(event)) {
@@ -5626,11 +5631,7 @@ namespace QuickMedia {
tab_shade_height = std::floor(tab_vertical_offset) + Tabs::get_height() + room_name_padding_y;
- float body_width = window_size.x - body_padding_horizontal * 2.0f;
- /*if(body_width <= 480.0f) {
- body_width = window_size.x;
- body_padding_horizontal = 0.0f;
- }*/
+ const float body_width = window_size.x;
this->body_pos = sf::Vector2f(0.0f, tab_shade_height);
if(window_size.x > 900.0f && show_room_side_panel) {
@@ -5641,19 +5642,19 @@ namespace QuickMedia {
draw_room_list = false;
}
- body_pos = sf::Vector2f(this->body_pos.x + this->body_size.x + body_padding_horizontal, body_padding_vertical + tab_shade_height);
- body_size = sf::Vector2f(body_width - this->body_pos.x - this->body_size.x, window_size.y - chat_input_height_full - body_padding_vertical - tab_shade_height);
+ body_pos = sf::Vector2f(this->body_pos.x + this->body_size.x, tab_shade_height);
+ body_size = sf::Vector2f(body_width - this->body_pos.x - this->body_size.x, window_size.y - chat_input_height_full - tab_shade_height);
- chat_input_shade.setSize(sf::Vector2f(window_size.x - (body_pos.x - body_padding_horizontal), chat_input_height_full));
- chat_input_shade.setPosition(body_pos.x - body_padding_horizontal, window_size.y - chat_input_shade.getSize().y);
+ chat_input_shade.setSize(sf::Vector2f(window_size.x - body_pos.x, chat_input_height_full));
+ chat_input_shade.setPosition(body_pos.x, window_size.y - chat_input_shade.getSize().y);
- chat_input.set_max_width(window_size.x - (logo_padding_x + logo_size.x + chat_input_padding_x + logo_padding_x + body_pos.x - body_padding_horizontal));
- chat_input.set_position(sf::Vector2f(std::floor(body_pos.x - body_padding_horizontal + logo_padding_x + logo_size.x + chat_input_padding_x), window_size.y - chat_height - chat_input_padding_y));
+ chat_input.set_max_width(window_size.x - (logo_padding_x + logo_size.x + chat_input_padding_x + logo_padding_x + body_pos.x));
+ chat_input.set_position(sf::Vector2f(std::floor(body_pos.x + logo_padding_x + logo_size.x + chat_input_padding_x), window_size.y - chat_height - chat_input_padding_y));
more_messages_below_rect.setSize(sf::Vector2f(chat_input_shade.getSize().x, gradient_height));
more_messages_below_rect.setPosition(chat_input_shade.getPosition().x, std::floor(window_size.y - chat_input_height_full - gradient_height));
- logo_sprite.setPosition(body_pos.x - body_padding_horizontal + logo_padding_x, std::floor(window_size.y - chat_input_height_full * 0.5f - logo_size.y * 0.5f));
+ logo_sprite.setPosition(body_pos.x + logo_padding_x, std::floor(window_size.y - chat_input_height_full * 0.5f - logo_size.y * 0.5f));
}
sync_data.messages.clear();
@@ -5746,14 +5747,12 @@ namespace QuickMedia {
} else {
tabs[selected_tab].body->draw(window, body_pos, body_size);
if(selected_tab == MESSAGES_TAB_INDEX && mention.visible && chat_state == ChatState::TYPING_MESSAGE) {
- sf::RectangleShape user_mention_background(sf::Vector2f(body_size.x + body_padding_vertical*2.0f, user_mention_body_height));
- user_mention_background.setPosition(sf::Vector2f(body_pos.x - body_padding_vertical, body_pos.y + body_size.y - user_mention_body_height));
+ sf::RectangleShape user_mention_background(sf::Vector2f(body_size.x, user_mention_body_height));
+ user_mention_background.setPosition(sf::Vector2f(body_pos.x, body_pos.y + body_size.y - user_mention_body_height));
user_mention_background.setFillColor(sf::Color(33, 37, 44));
window.draw(user_mention_background);
- tabs[USERS_TAB_INDEX].body->draw(window,
- user_mention_background.getPosition() + sf::Vector2f(body_padding_vertical, body_padding_vertical),
- user_mention_background.getSize() - sf::Vector2f(body_padding_vertical*2.0f, body_padding_vertical));
+ tabs[USERS_TAB_INDEX].body->draw(window, user_mention_background.getPosition(), user_mention_background.getSize());
}
}
@@ -5787,9 +5786,8 @@ namespace QuickMedia {
glScissor(0.0f, 0.0f, this->body_size.x, window_size.y);
window.draw(room_list_background);
window.draw(room_label);
- const float padding_x = std::floor(10.0f * get_ui_scale());
const float tab_y = std::floor(tab_vertical_offset) + room_name_padding_y;
- matrix_chat_page->rooms_page->body->draw(window, sf::Vector2f(padding_x, tab_y), sf::Vector2f(this->body_size.x - padding_x * 2.0f, window_size.y - tab_y), Json::Value::nullSingleton());
+ matrix_chat_page->rooms_page->body->draw(window, sf::Vector2f(0.0f, tab_y), sf::Vector2f(this->body_size.x, window_size.y - tab_y), Json::Value::nullSingleton());
glDisable(GL_SCISSOR_TEST);
}
@@ -5851,8 +5849,8 @@ namespace QuickMedia {
window.draw(user_mention_background);
tabs[USERS_TAB_INDEX].body->draw(window,
- sf::Vector2f(body_pos.x, item_background.getPosition().y - user_mention_body_height + body_padding_vertical),
- sf::Vector2f(body_size.x, user_mention_body_height - body_padding_vertical));
+ sf::Vector2f(body_pos.x, item_background.getPosition().y - user_mention_body_height),
+ sf::Vector2f(body_size.x, user_mention_body_height));
}
replying_to_text.setPosition(body_item_pos.x, body_item_pos.y - replying_to_text_height);
@@ -6028,7 +6026,7 @@ namespace QuickMedia {
auto rooms_tags_body = create_body();
auto matrix_rooms_tag_page = std::make_unique<MatrixRoomTagsPage>(this, rooms_tags_body.get());
- auto rooms_body = create_body();
+ auto rooms_body = create_body(true);
auto rooms_page_search_bar = create_search_bar("Search...", SEARCH_DELAY_FILTER);
auto matrix_rooms_page = std::make_unique<MatrixRoomsPage>(this, rooms_body.get(), "All rooms", nullptr, rooms_page_search_bar.get());
@@ -6453,7 +6451,7 @@ namespace QuickMedia {
const float loading_bar_padding_x = std::floor(4.0f * get_ui_scale());
const float loading_bar_padding_y = std::floor(4.0f * get_ui_scale());
RoundedRectangle loading_bar_background(sf::Vector2f(1.0f, 1.0f), std::floor(10.0f * get_ui_scale()), sf::Color(21, 25, 30), &rounded_rectangle_shader);
- RoundedRectangle loading_bar(sf::Vector2f(1.0f, 1.0f), std::floor(10.0f * get_ui_scale() - loading_bar_padding_y), sf::Color(0, 85, 119), &rounded_rectangle_shader);
+ RoundedRectangle loading_bar(sf::Vector2f(1.0f, 1.0f), std::floor(10.0f * get_ui_scale() - loading_bar_padding_y), sf::Color(31, 117, 255), &rounded_rectangle_shader);
const float padding_x = std::floor(30.0f * get_ui_scale());
const float spacing_y = std::floor(15.0f * get_ui_scale());
@@ -6634,7 +6632,7 @@ namespace QuickMedia {
cancel_button.set_background_color(sf::Color(41, 45, 50));
Button save_button("Save", FontLoader::get_font(FontLoader::FontType::LATIN), 16, 100.0f, &rounded_rectangle_shader, get_ui_scale());
- save_button.set_background_color(sf::Color(71, 75, 180));
+ save_button.set_background_color(sf::Color(31, 117, 255));
sf::Text file_name_label("File name:", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(16.0f * get_ui_scale()));