1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:37:34 +00:00

WindowServer+MenuApplets: Move the "Audio" applet to its own program

This patch introduces the second MenuApplet: Audio. To make this work,
menu applet windows now also receive mouse events.

There's still some problem with mute/unmute via clicking not actually
working, but the call goes from the applet program over IPC to the
AudioServer, where something goes wrong with the state change message.
Need to look at that separately.

Anyways, it's pretty cool to have more applets running in their own
separate processes. :^)
This commit is contained in:
Andreas Kling 2019-12-16 15:33:42 +01:00
parent df129bbe0e
commit e1940f365b
11 changed files with 98 additions and 46 deletions

View file

@ -0,0 +1,65 @@
#include <LibAudio/AClientConnection.h>
#include <LibGUI/GApplication.h>
#include <LibGUI/GPainter.h>
#include <LibGUI/GWidget.h>
#include <LibGUI/GWindow.h>
class AudioWidget final : public GWidget {
C_OBJECT(AudioWidget)
public:
AudioWidget()
: GWidget(nullptr)
{
m_audio_client = make<AClientConnection>();
m_audio_client->on_muted_state_change = [this](bool muted) {
dbg() << "Muted state changed: " << muted;
if (m_audio_muted == muted)
return;
m_audio_muted = muted;
update();
};
m_unmuted_bitmap = GraphicsBitmap::load_from_file("/res/icons/audio-unmuted.png");
m_muted_bitmap = GraphicsBitmap::load_from_file("/res/icons/audio-muted.png");
}
virtual ~AudioWidget() override {}
private:
virtual void mousedown_event(GMouseEvent& event) override
{
if (event.button() != GMouseButton::Left)
return;
dbg() << "set_muted: " << !m_audio_muted;
m_audio_client->set_muted(!m_audio_muted);
update();
}
virtual void paint_event(GPaintEvent& event) override
{
GPainter painter(*this);
painter.add_clip_rect(event.rect());
painter.clear_rect(event.rect(), Color::from_rgba(0));
auto& audio_bitmap = m_audio_muted ? *m_muted_bitmap : *m_unmuted_bitmap;
painter.blit({}, audio_bitmap, audio_bitmap.rect());
}
OwnPtr<AClientConnection> m_audio_client;
RefPtr<GraphicsBitmap> m_muted_bitmap;
RefPtr<GraphicsBitmap> m_unmuted_bitmap;
bool m_audio_muted { false };
};
int main(int argc, char** argv)
{
GApplication app(argc, argv);
auto window = GWindow::construct();
window->set_has_alpha_channel(true);
window->set_window_type(GWindowType::MenuApplet);
window->resize(12, 16);
auto widget = AudioWidget::construct();
window->set_main_widget(widget);
window->show();
return app.exec();
}