aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--include/Utils.hpp1
-rw-r--r--plugins/youtube/YoutubeMediaProxy.hpp4
-rw-r--r--src/AsyncImageLoader.cpp14
-rw-r--r--src/Config.cpp31
-rw-r--r--src/Utils.cpp7
-rw-r--r--src/plugins/youtube/YoutubeMediaProxy.cpp11
7 files changed, 37 insertions, 34 deletions
diff --git a/README.md b/README.md
index 4b3611c..fec9525 100644
--- a/README.md
+++ b/README.md
@@ -163,8 +163,7 @@ See [default.json](https://git.dec05eba.com/QuickMedia/plain/themes/default.json
If `xdg-open` is not installed then the `BROWSER` environment variable is used to open links in a browser.\
Set `QM_PHONE_FACTOR=1` to disable the room list side panel in matrix.
## UI scaling
-Set `GDK_SCALE` environment variable or add `Xft.dpi` to `$HOME/.Xresources` (`xrdb` which is part of the `xorg-xrdb` package needs to be installed).\
-For example a value of 96 for the `Xft.dpi` means 1.0 scaling and 144 (96*1.5) means 1.5 scaling.\
+Set `GDK_SCALE` environment variable or add `Xft.dpi` to `$HOME/.Xresources`. For example a value of 96 for the `Xft.dpi` means 1.0 scaling and 144 (96*1.5) means 1.5 scaling.\
Note that at the moment, images do also not scale above their original size.\
Scaling can also be set in `$HOME/quickmedia/config.json`, which will override `GDK_SCALE` and `$HOME/.Xresources` `Xft.dpi`.
## Tabs
diff --git a/include/Utils.hpp b/include/Utils.hpp
index 5f725bf..138d47e 100644
--- a/include/Utils.hpp
+++ b/include/Utils.hpp
@@ -11,6 +11,7 @@ namespace QuickMedia {
bool is_running_wayland();
time_t iso_utc_to_unix_time(const char *time_str);
std::string unix_time_to_local_time_str(time_t unix_time);
+ int64_t get_boottime_milliseconds();
sf::Vector2f vec2f_floor(float x, float y);
} \ No newline at end of file
diff --git a/plugins/youtube/YoutubeMediaProxy.hpp b/plugins/youtube/YoutubeMediaProxy.hpp
index cc797a9..8e6ea38 100644
--- a/plugins/youtube/YoutubeMediaProxy.hpp
+++ b/plugins/youtube/YoutubeMediaProxy.hpp
@@ -68,8 +68,8 @@ namespace QuickMedia {
bool download_header_remaining_sent = false;
int download_header_written_offset = 0;
int download_header_offset_to_end_of_header = 0;
- time_t download_start_time = 0;
- time_t throttle_start_time = 0;
+ int64_t download_start_time = 0;
+ int64_t throttle_start_time = 0;
int64_t total_downloaded_bytes = 0;
bool download_started = false;
bool throttle_started = false;
diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp
index fce745a..f926a8d 100644
--- a/src/AsyncImageLoader.cpp
+++ b/src/AsyncImageLoader.cpp
@@ -4,6 +4,7 @@
#include "../include/ImageUtils.hpp"
#include "../include/Scale.hpp"
#include "../include/SfmlFixes.hpp"
+#include "../include/Utils.hpp"
#include "../external/hash-library/sha256.h"
#include <unistd.h>
@@ -206,10 +207,6 @@ namespace QuickMedia {
thumbnail_load_data.thumbnail_data->loading_state = LoadingState::FINISHED_LOADING;
}
- static int64_t timeval_to_milliseconds(struct timeval &time) {
- return (int64_t)time.tv_sec * 1000 + (int64_t)time.tv_usec / 1000;
- }
-
AsyncImageLoader::AsyncImageLoader() {
for(int i = 0; i < NUM_IMAGE_LOAD_PARALLEL; ++i) {
downloads[i].read_program.pid = -1;
@@ -233,10 +230,7 @@ namespace QuickMedia {
Path tmp_thumbnail_path = download.thumbnail_path;
tmp_thumbnail_path.append(".tmp");
if(status == 0 && rename_atomic(tmp_thumbnail_path.data.c_str(), download.thumbnail_path.data.c_str()) == 0) {
- struct timeval time;
- gettimeofday(&time, nullptr);
- fprintf(stderr, "Download duration for %s: %ld ms\n", download.url.c_str(), timeval_to_milliseconds(time) - download.download_start);
-
+ fprintf(stderr, "Download duration for %s: %ld ms\n", download.url.c_str(), get_boottime_milliseconds() - download.download_start);
ThumbnailLoadData load_data = { std::move(download.url), std::move(download.thumbnail_path), false, download.thumbnail_data, download.resize_target_size };
process_thumbnail(load_data);
} else {
@@ -321,9 +315,7 @@ namespace QuickMedia {
return;
}
- struct timeval time;
- gettimeofday(&time, nullptr);
- downloads[free_index].download_start = timeval_to_milliseconds(time);
+ downloads[free_index].download_start = get_boottime_milliseconds();
downloads[free_index].thumbnail_path = std::move(thumbnail_path);
downloads[free_index].thumbnail_data = thumbnail_data;
downloads[free_index].resize_target_size = resize_target_size;
diff --git a/src/Config.cpp b/src/Config.cpp
index 266c45c..ada2113 100644
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -2,6 +2,8 @@
#include "../include/Storage.hpp"
#include <json/value.h>
#include <assert.h>
+#include <X11/Xlib.h>
+#include <X11/Xresource.h>
namespace QuickMedia {
static bool config_initialized = false;
@@ -14,20 +16,27 @@ namespace QuickMedia {
// Returns XFT_DPI_DEFAULT on error
static int xrdb_get_dpi() {
int xft_dpi = XFT_DPI_DEFAULT;
-
- FILE *xrdb_query = popen("xrdb -get Xft.dpi", "r");
- if(!xrdb_query)
+ Display *display = XOpenDisplay(nullptr);
+ if(!display) {
+ fprintf(stderr, "Failed to open x display\n");
return xft_dpi;
+ }
- char line[32];
- line[0] = '\0';
- fread(line, 1, sizeof(line), xrdb_query);
-
- const int xft_dpi_file = atoi(line);
- if(xft_dpi_file > 0)
- xft_dpi = xft_dpi_file;
+ XrmInitialize();
+
+ char *resource_manager = XResourceManagerString(display);
+ if(resource_manager) {
+ XrmDatabase db = XrmGetStringDatabase(resource_manager);
+ if(db) {
+ char *type;
+ XrmValue val;
+ if(XrmGetResource(db, "Xft.dpi", "*", &type, &val))
+ xft_dpi = strtol(val.addr, nullptr, 10);
+ XrmDestroyDatabase(db);
+ }
+ }
- pclose(xrdb_query);
+ XCloseDisplay(display);
return xft_dpi;
}
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 3e9fe7d..d466bee 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -78,6 +78,13 @@ namespace QuickMedia {
return time_str;
}
+ int64_t get_boottime_milliseconds() {
+ struct timespec time;
+ if(clock_gettime(CLOCK_BOOTTIME, &time) == -1 && errno == EINVAL)
+ clock_gettime(CLOCK_MONOTONIC, &time);
+ return (int64_t)time.tv_sec * 1000 + (int64_t)time.tv_nsec / 1000000;
+ }
+
sf::Vector2f vec2f_floor(float x, float y) {
return sf::Vector2f(int(x), int(y));
}
diff --git a/src/plugins/youtube/YoutubeMediaProxy.cpp b/src/plugins/youtube/YoutubeMediaProxy.cpp
index c5af20e..4fe6c74 100644
--- a/src/plugins/youtube/YoutubeMediaProxy.cpp
+++ b/src/plugins/youtube/YoutubeMediaProxy.cpp
@@ -1,5 +1,6 @@
#include "../../../plugins/youtube/YoutubeMediaProxy.hpp"
#include "../../../include/NetUtils.hpp"
+#include "../../../include/Utils.hpp"
#include <vector>
#include <stdio.h>
@@ -465,10 +466,7 @@ namespace QuickMedia {
total_downloaded_bytes = 0;
download_started = true;
throttle_started = false;
-
- struct timespec tp;
- clock_gettime(CLOCK_MONOTONIC, &tp);
- download_start_time = tp.tv_sec;
+ download_start_time = get_boottime_milliseconds();
}
total_downloaded_bytes += downloader_num_read_bytes;
}
@@ -476,10 +474,7 @@ namespace QuickMedia {
#if 0
if(download_started) {
- struct timespec tp;
- clock_gettime(CLOCK_MONOTONIC, &tp);
-
- int64_t time_elapsed = tp.tv_sec - download_start_time;
+ const int64_t time_elapsed_sec = (get_boottime_milliseconds() - download_start_time) / 1000;
int64_t download_speed_kb_sec = 0;
if(time_elapsed > 0)
download_speed_kb_sec = (total_downloaded_bytes / time_elapsed) / 1024;