mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-03-31 09:17:04 +09:00
Esc to close region selection
This commit is contained in:
@@ -28,6 +28,7 @@ namespace gsr {
|
||||
bool poll_events();
|
||||
bool is_selected() const;
|
||||
bool take_selection();
|
||||
bool take_canceled();
|
||||
Region get_selection() const;
|
||||
private:
|
||||
void on_button_press(const void *de);
|
||||
@@ -45,6 +46,7 @@ namespace gsr {
|
||||
Region region;
|
||||
bool selecting_region = false;
|
||||
bool selected = false;
|
||||
bool canceled = false;
|
||||
bool is_wayland = false;
|
||||
std::vector<Monitor> monitors;
|
||||
mgl::vec2i cursor_pos;
|
||||
|
||||
@@ -592,7 +592,9 @@ namespace gsr {
|
||||
|
||||
handle_keyboard_mapping_event();
|
||||
region_selector.poll_events();
|
||||
if(region_selector.take_selection() && on_region_selected) {
|
||||
if(region_selector.take_canceled()) {
|
||||
on_region_selected = nullptr;
|
||||
} else if(region_selector.take_selection() && on_region_selected) {
|
||||
on_region_selected();
|
||||
on_region_selected = nullptr;
|
||||
}
|
||||
@@ -635,7 +637,7 @@ namespace gsr {
|
||||
start_region_capture = false;
|
||||
hide();
|
||||
if(!region_selector.start(get_color_theme().tint_color)) {
|
||||
show_notification("Failed to start region capture", notification_error_timeout_seconds, mgl::Color(255, 0, 0, 0), mgl::Color(255, 0, 0, 0), NotificationType::RECORD);
|
||||
show_notification("Failed to start region capture", notification_error_timeout_seconds, mgl::Color(255, 0, 0, 0), mgl::Color(255, 0, 0, 0), NotificationType::NONE);
|
||||
on_region_selected = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace gsr {
|
||||
const Window window = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, width, height, 0, vinfo->depth, InputOutput, vinfo->visual, CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWEventMask | CWColormap, &window_attr);
|
||||
if(window) {
|
||||
set_window_size_not_resizable(dpy, window, width, height);
|
||||
set_window_shape_cross(dpy, window, width, height, 5);
|
||||
set_window_shape_cross(dpy, window, width, height, cursor_thickness);
|
||||
make_window_click_through(dpy, window);
|
||||
}
|
||||
return window;
|
||||
@@ -148,7 +148,7 @@ namespace gsr {
|
||||
const int y = cursor_y - cursor_window_size / 2;
|
||||
XFillRectangle(dpy, window, cursor_gc, x + cursor_window_size / 2 - thickness / 2 , y, thickness, cursor_window_size);
|
||||
XFillRectangle(dpy, window, cursor_gc, x, y + cursor_window_size / 2 - thickness / 2, cursor_window_size, thickness);
|
||||
} else {
|
||||
} else if(cursor_window) {
|
||||
XMoveWindow(dpy, cursor_window, cursor_x - cursor_window_size / 2, cursor_y - cursor_window_size / 2);
|
||||
}
|
||||
XFlush(dpy);
|
||||
@@ -253,6 +253,7 @@ namespace gsr {
|
||||
hide_window_from_taskbar(dpy, region_window);
|
||||
XFixesHideCursor(dpy, region_window);
|
||||
XGrabPointer(dpy, DefaultRootWindow(dpy), True, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
|
||||
XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync, GrabModeAsync, CurrentTime);
|
||||
xi_grab_all_mouse_devices(dpy);
|
||||
XFlush(dpy);
|
||||
|
||||
@@ -271,6 +272,7 @@ namespace gsr {
|
||||
|
||||
XFlush(dpy);
|
||||
selected = false;
|
||||
canceled = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -283,6 +285,7 @@ namespace gsr {
|
||||
XFixesShowCursor(dpy, region_window);
|
||||
|
||||
XUngrabPointer(dpy, CurrentTime);
|
||||
XUngrabKeyboard(dpy, CurrentTime);
|
||||
xi_ungrab_all_mouse_devices(dpy);
|
||||
XFlush(dpy);
|
||||
|
||||
@@ -326,6 +329,14 @@ namespace gsr {
|
||||
XEvent xev;
|
||||
while(XPending(dpy)) {
|
||||
XNextEvent(dpy, &xev);
|
||||
|
||||
if(xev.type == KeyRelease && XKeycodeToKeysym(dpy, xev.xkey.keycode, 0) == XK_Escape) {
|
||||
canceled = true;
|
||||
selected = false;
|
||||
stop();
|
||||
break;
|
||||
}
|
||||
|
||||
XGenericEventCookie *cookie = &xev.xcookie;
|
||||
if(cookie->type != GenericEvent || cookie->extension != xi_opcode || !XGetEventData(dpy, cookie))
|
||||
continue;
|
||||
@@ -365,6 +376,12 @@ namespace gsr {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool RegionSelector::take_canceled() {
|
||||
const bool result = canceled;
|
||||
canceled = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
Region RegionSelector::get_selection() const {
|
||||
return region;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user