mirror of
				https://github.com/rad4day/Waybar.git
				synced 2025-11-04 01:32:42 +01:00 
			
		
		
		
	Do not crash when a monitor is removed
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <deque>
 | 
			
		||||
#include <list>
 | 
			
		||||
#include <functional>
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <mutex>
 | 
			
		||||
@@ -7,11 +7,19 @@
 | 
			
		||||
#include <thread>
 | 
			
		||||
 | 
			
		||||
namespace waybar::modules::hyprland {
 | 
			
		||||
 | 
			
		||||
class EventHandler {
 | 
			
		||||
public:
 | 
			
		||||
  virtual void onEvent(const std::string& ev) = 0;
 | 
			
		||||
  virtual ~EventHandler() = default;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class IPC {
 | 
			
		||||
 public:
 | 
			
		||||
  IPC() { startIPC(); }
 | 
			
		||||
 | 
			
		||||
  void registerForIPC(const std::string&, std::function<void(const std::string&)>);
 | 
			
		||||
  void registerForIPC(const std::string&, EventHandler*);
 | 
			
		||||
  void unregisterForIPC(EventHandler*);
 | 
			
		||||
 | 
			
		||||
  std::string getSocket1Reply(const std::string& rq);
 | 
			
		||||
 | 
			
		||||
@@ -20,7 +28,7 @@ class IPC {
 | 
			
		||||
  void parseIPC(const std::string&);
 | 
			
		||||
 | 
			
		||||
  std::mutex callbackMutex;
 | 
			
		||||
  std::deque<std::pair<std::string, std::function<void(const std::string&)>>> callbacks;
 | 
			
		||||
  std::list<std::pair<std::string, EventHandler*>> callbacks;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
inline std::unique_ptr<IPC> gIPC;
 | 
			
		||||
 
 | 
			
		||||
@@ -7,10 +7,11 @@
 | 
			
		||||
 | 
			
		||||
namespace waybar::modules::hyprland {
 | 
			
		||||
 | 
			
		||||
class Language : public waybar::AButton {
 | 
			
		||||
class Language : public waybar::AButton,
 | 
			
		||||
public EventHandler {
 | 
			
		||||
 public:
 | 
			
		||||
  Language(const std::string&, const waybar::Bar&, const Json::Value&);
 | 
			
		||||
  ~Language() = default;
 | 
			
		||||
  ~Language();
 | 
			
		||||
 | 
			
		||||
  auto update() -> void;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -9,10 +9,11 @@
 | 
			
		||||
 | 
			
		||||
namespace waybar::modules::hyprland {
 | 
			
		||||
 | 
			
		||||
class Window : public waybar::ALabel {
 | 
			
		||||
class Window : public waybar::ALabel,
 | 
			
		||||
 public EventHandler {
 | 
			
		||||
 public:
 | 
			
		||||
  Window(const std::string&, const waybar::Bar&, const Json::Value&);
 | 
			
		||||
  ~Window() = default;
 | 
			
		||||
  ~Window();
 | 
			
		||||
 | 
			
		||||
  auto update() -> void;
 | 
			
		||||
 | 
			
		||||
@@ -28,4 +29,4 @@ class Window : public waybar::ALabel {
 | 
			
		||||
  std::string lastView;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}  // namespace waybar::modules::hyprland
 | 
			
		||||
}  // namespace waybar::modules::hyprland
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user