Skip to content

Commit

Permalink
naming changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jstkdng committed Feb 25, 2024
1 parent 082e34e commit 5c17bc1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 34 deletions.
5 changes: 3 additions & 2 deletions include/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "canvas.hpp"
#include "flags.hpp"
#include "os.hpp"
#include "terminal.hpp"
#include "util/ptr.hpp"

Expand All @@ -40,11 +41,11 @@ class Application
void command_loop();
void handle_tmux_hook(std::string_view hook);

static std::atomic<bool> stop_flag; // NOLINT
inline static std::atomic<bool> stop_flag = false; // NOLINT
inline static const int parent_pid = os::get_ppid();

static void print_version();
static void print_header();
static const pid_t parent_pid;

private:
std::unique_ptr<Terminal> terminal;
Expand Down
21 changes: 5 additions & 16 deletions src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "application.hpp"
#include "image.hpp"
#include "os.hpp"
#include "tmux.hpp"
#include "util.hpp"
#include "util/socket.hpp"
Expand All @@ -35,9 +34,6 @@
using njson = nlohmann::json;
namespace fs = std::filesystem;

std::atomic<bool> Application::stop_flag{false}; // NOLINT
const pid_t Application::parent_pid = os::get_ppid();

Application::Application(const char *executable)
{
flags = Flags::instance();
Expand Down Expand Up @@ -197,19 +193,16 @@ void Application::command_loop()
if (flags->no_stdin) {
return;
}
while (true) {
while (!stop_flag) {
try {
const auto in_event = os::wait_for_data_on_stdin(100);
if (stop_flag.load()) {
break;
}
if (!in_event) {
continue;
}
const auto cmd = os::read_data_from_stdin();
execute(cmd);
} catch (const std::system_error &err) {
stop_flag.store(true);
stop_flag = true;
break;
}
}
Expand All @@ -222,15 +215,11 @@ void Application::socket_loop()

const int waitms = 100;
int conn = -1;
while (true) {
while (!stop_flag) {
try {
conn = socket.wait_for_connections(waitms);
} catch (const std::system_error &err) {
stop_flag.store(true);
break;
}

if (stop_flag.load()) {
stop_flag = true;
break;
}

Expand All @@ -241,7 +230,7 @@ void Application::socket_loop()
const auto data = socket.read_data_from_connection(conn);
for (const auto &cmd : data) {
if (cmd == "EXIT") {
stop_flag.store(true);
stop_flag = true;
return;
}
execute(cmd);
Expand Down
8 changes: 2 additions & 6 deletions src/canvas/wayland/wayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void WaylandCanvas::handle_events()
const auto wl_fd = wl_display_get_fd(display);
bool in_event = false;

while (true) {
while (!Application::stop_flag) {
// prepare to read wayland events
while (wl_display_prepare_read(display) != 0) {
wl_display_dispatch_pending(display);
Expand All @@ -202,11 +202,7 @@ void WaylandCanvas::handle_events()
try {
in_event = os::wait_for_data_on_fd(wl_fd, waitms);
} catch (const std::system_error &err) {
Application::stop_flag.store(true);
break;
}

if (Application::stop_flag.load()) {
Application::stop_flag = true;
break;
}

Expand Down
2 changes: 0 additions & 2 deletions src/canvas/wayland/wayland.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "wayland-xdg-shell-client-protocol.h"
#include "window/waylandwindow.hpp"

#include <atomic>
#include <memory>
#include <thread>
#include <unordered_map>
Expand Down Expand Up @@ -65,7 +64,6 @@ class WaylandCanvas : public Canvas
private:
struct wl_display *display = nullptr;
struct wl_registry *registry = nullptr;
std::atomic<bool> stop_flag{false};
std::thread event_handler;

std::shared_ptr<spdlog::logger> logger;
Expand Down
8 changes: 2 additions & 6 deletions src/canvas/x11/x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,11 @@ void X11Canvas::handle_events()
const int connfd = xcb_get_file_descriptor(connection);
bool status = false;

while (true) {
while (!Application::stop_flag) {
try {
status = os::wait_for_data_on_fd(connfd, waitms);
} catch (const std::system_error &err) {
Application::stop_flag.store(true);
break;
}

if (Application::stop_flag.load()) {
Application::stop_flag = true;
break;
}

Expand Down
3 changes: 1 addition & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@

void signal_handler(const int signal)
{
auto &flag = Application::stop_flag;
flag.store(true);
Application::stop_flag = true;

const auto logger = spdlog::get("main");
if (!logger) {
Expand Down

0 comments on commit 5c17bc1

Please sign in to comment.