refactor(pulseaudio): proper scroll override
This commit is contained in:
		
							parent
							
								
									cda6282277
								
							
						
					
					
						commit
						527144a440
					
				|  | @ -21,14 +21,13 @@ class Pulseaudio : public ALabel { | ||||||
|   static void sourceInfoCb(pa_context*, const pa_source_info* i, int, void* data); |   static void sourceInfoCb(pa_context*, const pa_source_info* i, int, void* data); | ||||||
|   static void serverInfoCb(pa_context*, const pa_server_info*, void*); |   static void serverInfoCb(pa_context*, const pa_server_info*, void*); | ||||||
|   static void volumeModifyCb(pa_context*, int, void*); |   static void volumeModifyCb(pa_context*, int, void*); | ||||||
|   bool        handleVolume(GdkEventScroll* e); |  | ||||||
| 
 | 
 | ||||||
|  |   bool              handleScroll(GdkEventScroll* e); | ||||||
|   const std::string getPortIcon() const; |   const std::string getPortIcon() const; | ||||||
| 
 | 
 | ||||||
|   pa_threaded_mainloop* mainloop_; |   pa_threaded_mainloop* mainloop_; | ||||||
|   pa_mainloop_api*      mainloop_api_; |   pa_mainloop_api*      mainloop_api_; | ||||||
|   pa_context*           context_; |   pa_context*           context_; | ||||||
|   std::mutex            mutex_; |  | ||||||
|   // SINK
 |   // SINK
 | ||||||
|   uint32_t    sink_idx_{0}; |   uint32_t    sink_idx_{0}; | ||||||
|   uint16_t    volume_; |   uint16_t    volume_; | ||||||
|  |  | ||||||
|  | @ -31,13 +31,6 @@ waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value | ||||||
|     throw std::runtime_error("pa_mainloop_run() failed."); |     throw std::runtime_error("pa_mainloop_run() failed."); | ||||||
|   } |   } | ||||||
|   pa_threaded_mainloop_unlock(mainloop_); |   pa_threaded_mainloop_unlock(mainloop_); | ||||||
| 
 |  | ||||||
|   // define the pulse scroll events only when no user provided
 |  | ||||||
|   // events are configured
 |  | ||||||
|   if (!config["on-scroll-up"].isString() && !config["on-scroll-down"].isString()) { |  | ||||||
|     event_box_.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK); |  | ||||||
|     event_box_.signal_scroll_event().connect(sigc::mem_fun(*this, &Pulseaudio::handleVolume)); |  | ||||||
|   } |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| waybar::modules::Pulseaudio::~Pulseaudio() { | waybar::modules::Pulseaudio::~Pulseaudio() { | ||||||
|  | @ -73,11 +66,13 @@ void waybar::modules::Pulseaudio::contextStateCb(pa_context *c, void *data) { | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool waybar::modules::Pulseaudio::handleVolume(GdkEventScroll *e) { | bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll *e) { | ||||||
|   // Avoid concurrent scroll event
 |   // change the pulse volume only when no user provided
 | ||||||
|   std::lock_guard<std::mutex> lock(mutex_); |   // events are configured
 | ||||||
| 
 |   if (config["on-scroll-up"].isString() || config["on-scroll-down"].isString()) { | ||||||
|   auto dir = ALabel::getScrollDir(e); |     return AModule::handleScroll(e); | ||||||
|  |   } | ||||||
|  |   auto dir = AModule::getScrollDir(e); | ||||||
|   if (dir == SCROLL_DIR::NONE) { |   if (dir == SCROLL_DIR::NONE) { | ||||||
|     return true; |     return true; | ||||||
|   } |   } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue