diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Overlay.cpp | 40 | ||||
-rw-r--r-- | src/Process.cpp | 8 | ||||
-rw-r--r-- | src/gui/CustomRendererWidget.cpp | 2 | ||||
-rw-r--r-- | src/gui/GsrPage.cpp | 2 | ||||
-rw-r--r-- | src/gui/ScrollablePage.cpp | 18 | ||||
-rw-r--r-- | src/gui/SettingsPage.cpp | 5 | ||||
-rw-r--r-- | src/gui/StaticPage.cpp | 2 |
7 files changed, 59 insertions, 18 deletions
diff --git a/src/Overlay.cpp b/src/Overlay.cpp index d306910..da3758e 100644 --- a/src/Overlay.cpp +++ b/src/Overlay.cpp @@ -19,6 +19,7 @@ #include <sys/wait.h> #include <limits.h> #include <fcntl.h> +#include <poll.h> #include <stdexcept> #include <X11/Xlib.h> @@ -299,10 +300,11 @@ namespace gsr { } static mgl::vec2i create_window_get_center_position(Display *display) { + const int size = 16; XSetWindowAttributes window_attr; window_attr.event_mask = StructureNotifyMask; window_attr.background_pixel = 0; - const Window window = XCreateWindow(display, DefaultRootWindow(display), 0, 0, 16, 16, 0, CopyFromParent, InputOutput, CopyFromParent, CWBackPixel | CWEventMask, &window_attr); + const Window window = XCreateWindow(display, DefaultRootWindow(display), 0, 0, size, size, 0, CopyFromParent, InputOutput, CopyFromParent, CWBackPixel | CWEventMask, &window_attr); if(!window) return {0, 0}; @@ -321,12 +323,36 @@ namespace gsr { const unsigned long opacity = (unsigned long)(0xFFFFFFFFul * alpha); XChangeProperty(display, window, net_wm_window_opacity, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&opacity, 1L); + XSizeHints *size_hints = XAllocSizeHints(); + size_hints->width = size; + size_hints->min_width = size; + size_hints->max_width = size; + size_hints->height = size; + size_hints->min_height = size; + size_hints->max_height = size; + size_hints->flags = PSize | PMinSize | PMaxSize; + XSetWMNormalHints(display, window, size_hints); + XFree(size_hints); + XMapWindow(display, window); XFlush(display); + const int x_fd = XConnectionNumber(display); mgl::vec2i window_pos; XEvent xev; while(true) { + struct pollfd poll_fd; + poll_fd.fd = x_fd; + poll_fd.events = POLLIN; + poll_fd.revents = 0; + const int fds_ready = poll(&poll_fd, 1, 1000); + if(fds_ready == 0) { + fprintf(stderr, "Error: timed out waiting for ConfigureNotify after XCreateWindow\n"); + break; + } else if(fds_ready == -1 || !(poll_fd.revents & POLLIN)) { + continue; + } + XNextEvent(display, &xev); if(xev.type == ConfigureNotify) { window_pos.x = xev.xconfigure.x + xev.xconfigure.width / 2; @@ -1545,12 +1571,12 @@ namespace gsr { static bool validate_capture_target(const GsrInfo &gsr_info, const std::string &capture_target) { const SupportedCaptureOptions capture_options = get_supported_capture_options(gsr_info); // TODO: Also check x11 window when enabled (check if capture_target is a decminal/hex number) - if(capture_target == "focused" && !capture_options.focused) { - return false; - } else if(capture_target == "screen" && !capture_options.screen) { - return false; - } else if(capture_target == "portal" && !capture_options.portal) { - return false; + if(capture_target == "focused") { + return capture_options.focused; + } else if(capture_target == "screen") { + return capture_options.screen; + } else if(capture_target == "portal") { + return capture_options.portal; } else { for(const GsrMonitor &monitor : capture_options.monitors) { if(capture_target == monitor.name) diff --git a/src/Process.cpp b/src/Process.cpp index a8e5fb5..a9c5103 100644 --- a/src/Process.cpp +++ b/src/Process.cpp @@ -29,7 +29,7 @@ namespace gsr { debug_print_args(args); - pid_t pid = vfork(); + const pid_t pid = vfork(); if(pid == -1) { perror("Failed to vfork"); return false; @@ -38,7 +38,7 @@ namespace gsr { signal(SIGHUP, SIG_IGN); // Daemonize child to make the parent the init process which will reap the zombie child - pid_t second_child = vfork(); + const pid_t second_child = vfork(); if(second_child == 0) { // child execvp(args[0], (char* const*)args); perror("execvp"); @@ -68,7 +68,7 @@ namespace gsr { debug_print_args(args); - pid_t pid = vfork(); + const pid_t pid = vfork(); if(pid == -1) { close(fds[PIPE_READ]); close(fds[PIPE_WRITE]); @@ -95,7 +95,7 @@ namespace gsr { int exec_program_get_stdout(const char **args, std::string &result) { result.clear(); int read_fd = -1; - pid_t process_id = exec_program(args, &read_fd); + const pid_t process_id = exec_program(args, &read_fd); if(process_id == -1) return -1; diff --git a/src/gui/CustomRendererWidget.cpp b/src/gui/CustomRendererWidget.cpp index cfb113b..4cb7adf 100644 --- a/src/gui/CustomRendererWidget.cpp +++ b/src/gui/CustomRendererWidget.cpp @@ -20,7 +20,7 @@ namespace gsr { mgl_scissor prev_scissor; mgl_window_get_scissor(window.internal_window(), &prev_scissor); - mgl_scissor new_scissor = { + const mgl_scissor new_scissor = { mgl_vec2i{(int)draw_pos.x, (int)draw_pos.y}, mgl_vec2i{(int)size.x, (int)size.y} }; diff --git a/src/gui/GsrPage.cpp b/src/gui/GsrPage.cpp index e6ee5fc..68ee292 100644 --- a/src/gui/GsrPage.cpp +++ b/src/gui/GsrPage.cpp @@ -106,7 +106,7 @@ namespace gsr { mgl_window_get_scissor(window.internal_window(), &prev_scissor); const mgl::vec2f inner_size = get_inner_size(); - mgl_scissor new_scissor = { + const mgl_scissor new_scissor = { mgl_vec2i{(int)position.x, (int)position.y}, mgl_vec2i{(int)inner_size.x, (int)inner_size.y} }; diff --git a/src/gui/ScrollablePage.cpp b/src/gui/ScrollablePage.cpp index 74dd715..94da907 100644 --- a/src/gui/ScrollablePage.cpp +++ b/src/gui/ScrollablePage.cpp @@ -19,9 +19,23 @@ namespace gsr { if(!visible) return true; - offset = position + offset + mgl::vec2f(0.0f, scroll_y); + offset = position + offset; + + const mgl::vec2f content_size = get_inner_size(); + const mgl::vec2i scissor_pos(offset.x, offset.y); + const mgl::vec2i scissor_size(content_size.x, content_size.y); + + offset.y += scroll_y; Widget *selected_widget = selected_child_widget; + if(event.type == mgl::Event::MouseButtonPressed || event.type == mgl::Event::MouseButtonReleased) { + if(!mgl::IntRect(scissor_pos, scissor_size).contains({event.mouse_button.x, event.mouse_button.y})) + return true; + } else if(event.type == mgl::Event::MouseMoved) { + if(!mgl::IntRect(scissor_pos, scissor_size).contains({event.mouse_move.x, event.mouse_move.y})) + return true; + } + if(event.type == mgl::Event::MouseButtonReleased && moving_scrollbar_with_cursor) { moving_scrollbar_with_cursor = false; remove_widget_as_selected_in_parent(); @@ -79,7 +93,7 @@ namespace gsr { mgl_window_get_scissor(window.internal_window(), &prev_scissor); const mgl::vec2f content_size = get_inner_size(); - mgl_scissor new_scissor = { + const mgl_scissor new_scissor = { mgl_vec2i{(int)offset.x, (int)offset.y}, mgl_vec2i{(int)content_size.x, (int)content_size.y} }; diff --git a/src/gui/SettingsPage.cpp b/src/gui/SettingsPage.cpp index dc6f2c7..28821d1 100644 --- a/src/gui/SettingsPage.cpp +++ b/src/gui/SettingsPage.cpp @@ -64,8 +64,9 @@ namespace gsr { // record_area_box->add_item("Window", "window"); if(capture_options.focused) record_area_box->add_item("Follow focused window", "focused"); - if(capture_options.screen) - record_area_box->add_item("All monitors", "screen"); + // Do we really need this? it's only available on nvidia x11 + //if(capture_options.screen) + // record_area_box->add_item("All monitors", "screen"); for(const auto &monitor : capture_options.monitors) { char name[256]; snprintf(name, sizeof(name), "Monitor %s (%dx%d)", monitor.name.c_str(), monitor.size.x, monitor.size.y); diff --git a/src/gui/StaticPage.cpp b/src/gui/StaticPage.cpp index a89fc42..c014f38 100644 --- a/src/gui/StaticPage.cpp +++ b/src/gui/StaticPage.cpp @@ -39,7 +39,7 @@ namespace gsr { mgl_scissor prev_scissor; mgl_window_get_scissor(window.internal_window(), &prev_scissor); - mgl_scissor new_scissor = { + const mgl_scissor new_scissor = { mgl_vec2i{(int)draw_pos.x, (int)draw_pos.y}, mgl_vec2i{(int)size.x, (int)size.y} }; |