mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-03-31 09:17:04 +09:00
Properly close program when disconnected from the X server
This commit is contained in:
Submodule depends/mglpp updated: 9800cff631...7f0a03d90e
@@ -642,11 +642,11 @@ namespace gsr {
|
||||
make_window_sticky(display, window->get_system_handle());
|
||||
hide_window_from_taskbar(display, window->get_system_handle());
|
||||
|
||||
if(default_cursor) {
|
||||
XFreeCursor(display, default_cursor);
|
||||
default_cursor = 0;
|
||||
}
|
||||
default_cursor = XCreateFontCursor(display, XC_arrow);
|
||||
// if(default_cursor) {
|
||||
// XFreeCursor(display, default_cursor);
|
||||
// default_cursor = 0;
|
||||
// }
|
||||
// default_cursor = XCreateFontCursor(display, XC_arrow);
|
||||
|
||||
// TODO: Retry if these fail.
|
||||
// TODO: Hmm, these dont work in owlboy. Maybe owlboy uses xi2 and that breaks this (does it?).
|
||||
@@ -701,14 +701,14 @@ namespace gsr {
|
||||
page_stack.pop();
|
||||
}
|
||||
|
||||
if(default_cursor) {
|
||||
XFreeCursor(display, default_cursor);
|
||||
default_cursor = 0;
|
||||
}
|
||||
// if(default_cursor) {
|
||||
// XFreeCursor(display, default_cursor);
|
||||
// default_cursor = 0;
|
||||
// }
|
||||
|
||||
XUngrabKeyboard(display, CurrentTime);
|
||||
XUngrabPointer(display, CurrentTime);
|
||||
XFlush(display);
|
||||
// XUngrabKeyboard(display, CurrentTime);
|
||||
// XUngrabPointer(display, CurrentTime);
|
||||
// XFlush(display);
|
||||
|
||||
window_texture_deinit(&window_texture);
|
||||
window_texture_sprite.set_texture(nullptr);
|
||||
|
||||
21
src/main.cpp
21
src/main.cpp
@@ -8,7 +8,6 @@
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <thread>
|
||||
|
||||
#include <X11/keysym.h>
|
||||
@@ -39,13 +38,6 @@ static void disable_prime_run() {
|
||||
unsetenv("__VK_LAYER_NV_optimus");
|
||||
}
|
||||
|
||||
static bool is_socket_disconnected(int socket) {
|
||||
char buf = '\0';
|
||||
errno = 0;
|
||||
const ssize_t bytes_read = recv(socket, &buf, 1, MSG_PEEK | MSG_DONTWAIT);
|
||||
return bytes_read == 0 || (bytes_read == -1 && (errno == EBADF || errno == ENOTCONN));
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
setlocale(LC_ALL, "C"); // Sigh... stupid C
|
||||
|
||||
@@ -70,7 +62,7 @@ int main(void) {
|
||||
signal(SIGINT, sigint_handler);
|
||||
|
||||
if(mgl_init() != 0) {
|
||||
fprintf(stderr, "error: failed to initialize mgl. Either failed to connec to the X11 server or failed to setup opengl\n");
|
||||
fprintf(stderr, "error: failed to initialize mgl. Failed to either connect to the X11 server or setup opengl\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -199,19 +191,16 @@ int main(void) {
|
||||
fprintf(stderr, "error: failed to register hotkey alt+f10 for saving replay because the hotkey is registered by another program\n");
|
||||
|
||||
mgl::Clock frame_delta_clock;
|
||||
while(running) {
|
||||
if(is_socket_disconnected(x11_socket)) {
|
||||
fprintf(stderr, "info: the X11 server has shutdown\n");
|
||||
break;
|
||||
}
|
||||
|
||||
while(running && mgl_is_connected_to_display_server()) {
|
||||
const double frame_delta_seconds = frame_delta_clock.restart();
|
||||
gsr::set_frame_delta_seconds(frame_delta_seconds);
|
||||
|
||||
global_hotkeys.poll_events();
|
||||
overlay->handle_events();
|
||||
if(!overlay->draw())
|
||||
if(!overlay->draw()) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
mgl_ping_display_server();
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "info: shutting down!\n");
|
||||
|
||||
Reference in New Issue
Block a user