summaryrefslogtreecommitdiff
path: root/MenuApplets
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-12-16 15:33:42 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-12-16 15:33:42 +0100
commite1940f365be62435c815b3cd6a022356840edb10 (patch)
treeaf85f767a0c887f593acbd3b933c7f882bc99b29 /MenuApplets
parentdf129bbe0e3d300a9a35a966af4ee323ced90cda (diff)
downloadserenity-e1940f365be62435c815b3cd6a022356840edb10.zip
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. :^)
Diffstat (limited to 'MenuApplets')
-rwxr-xr-xMenuApplets/Audio/Audio.MenuAppletbin0 -> 1410124 bytes
-rwxr-xr-xMenuApplets/Audio/Makefile7
-rw-r--r--MenuApplets/Audio/main.cpp65
3 files changed, 72 insertions, 0 deletions
diff --git a/MenuApplets/Audio/Audio.MenuApplet b/MenuApplets/Audio/Audio.MenuApplet
new file mode 100755
index 0000000000..dd4c89fcf9
--- /dev/null
+++ b/MenuApplets/Audio/Audio.MenuApplet
Binary files differ
diff --git a/MenuApplets/Audio/Makefile b/MenuApplets/Audio/Makefile
new file mode 100755
index 0000000000..cd0292e1ef
--- /dev/null
+++ b/MenuApplets/Audio/Makefile
@@ -0,0 +1,7 @@
+include ../../Makefile.common
+
+OBJS = main.o
+
+APP = Audio.MenuApplet
+
+include ../Makefile.common
diff --git a/MenuApplets/Audio/main.cpp b/MenuApplets/Audio/main.cpp
new file mode 100644
index 0000000000..bbd55f750c
--- /dev/null
+++ b/MenuApplets/Audio/main.cpp
@@ -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();
+}