Skip to content

Commit

Permalink
shell: fix mingw build
Browse files Browse the repository at this point in the history
  • Loading branch information
flightlessmango committed Apr 4, 2024
1 parent 3c743a9 commit 325498d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/hud_elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1658,11 +1658,13 @@ void HudElements::legacy_elements(){
}

void HudElements::update_exec(){
#ifdef __LINUX__
if (!HUDElements.shell)
HUDElements.shell = std::make_unique<Shell>();

for(auto& item : exec_list)
item.ret = HUDElements.shell->exec(item.value + "\n");
#endif
}

HudElements HUDElements;
2 changes: 2 additions & 0 deletions src/hud_elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class HudElements{
int refresh = 0;
std::unique_ptr<WineSync> winesync_ptr = nullptr;
std::unique_ptr<Net> net = nullptr;
#ifdef __LINUX__
std::unique_ptr<Shell> shell = nullptr;
#endif

void sort_elements(const std::pair<std::string, std::string>& option);
void legacy_elements();
Expand Down
4 changes: 4 additions & 0 deletions src/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include <fcntl.h>
#include <unistd.h>
#include <cstring>
#ifdef __LINUX__
#include <sys/wait.h>
#endif
#include <string>
#include <memory>

Expand All @@ -12,10 +14,12 @@ class Shell {
int from_shell[2];
pid_t shell_pid;

#ifdef __LINUX__
void setNonBlocking(int fd) {
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
}
#endif

void writeCommand(const std::string& command) {
write(to_shell[1], command.c_str(), command.length());
Expand Down

0 comments on commit 325498d

Please sign in to comment.