mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 16:45:03 +00:00
This patch also adds a Format concept to GraphicsBitmap. For now there are only two formats: RGB32 and RGBA32. Windows with alpha channel have their backing stores created in the RGBA32 format. Use this to make Terminal windows semi-transparent for that comfy rice look. There is one problem here, in that window compositing overdraw incurs multiple passes of blending of the same pixels. This leads to a mismatch in opacity which is obviously not good. I will work on this in a later patch. The alpha blending is currently straight C++. It should be relatively easy to optimize this using SSE instructions. For now I'm just happy with the cute effect. :^)
78 lines
2.1 KiB
C++
78 lines
2.1 KiB
C++
#include <SharedGraphics/GraphicsBitmap.h>
|
|
#include <LibGUI/GWindow.h>
|
|
#include <LibGUI/GWidget.h>
|
|
#include <LibGUI/GButton.h>
|
|
#include <LibGUI/GApplication.h>
|
|
#include <sys/wait.h>
|
|
#include <signal.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
|
|
static GWindow* make_launcher_window();
|
|
|
|
void handle_sigchld(int)
|
|
{
|
|
dbgprintf("Launcher(%d) Got SIGCHLD\n", getpid());
|
|
int pid = waitpid(-1, nullptr, 0);
|
|
dbgprintf("Launcher(%d) waitpid() returned %d\n", getpid(), pid);
|
|
ASSERT(pid > 0);
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
GApplication app(argc, argv);
|
|
|
|
signal(SIGCHLD, handle_sigchld);
|
|
|
|
auto* launcher_window = make_launcher_window();
|
|
launcher_window->set_should_exit_app_on_close(true);
|
|
launcher_window->show();
|
|
|
|
return app.exec();
|
|
}
|
|
|
|
class LauncherButton final : public GButton {
|
|
public:
|
|
LauncherButton(const String& icon_path, const String& exec_path, GWidget* parent)
|
|
: GButton(parent)
|
|
, m_executable_path(exec_path)
|
|
{
|
|
set_icon(GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, icon_path, { 32, 32 }));
|
|
resize(50, 50);
|
|
on_click = [this] (GButton&) {
|
|
pid_t child_pid = fork();
|
|
if (!child_pid) {
|
|
int rc = execl(m_executable_path.characters(), m_executable_path.characters(), nullptr);
|
|
if (rc < 0)
|
|
perror("execl");
|
|
}
|
|
};
|
|
}
|
|
virtual ~LauncherButton() { }
|
|
|
|
private:
|
|
String m_executable_path;
|
|
};
|
|
|
|
GWindow* make_launcher_window()
|
|
{
|
|
auto* window = new GWindow;
|
|
window->set_title("Launcher");
|
|
window->set_rect(50, 50, 300, 60);
|
|
|
|
auto* widget = new GWidget;
|
|
window->set_main_widget(widget);
|
|
|
|
auto* terminal_button = new LauncherButton("/res/icons/Terminal.rgb", "/bin/Terminal", widget);
|
|
terminal_button->move_to(5, 5);
|
|
|
|
auto* font_editor_button = new LauncherButton("/res/icons/FontEditor.rgb", "/bin/FontEditor", widget);
|
|
font_editor_button->move_to(60, 5);
|
|
|
|
auto* file_manager_button = new LauncherButton("/res/icons/FileManager.rgb", "/bin/FileManager", widget);
|
|
file_manager_button->move_to(115, 5);
|
|
|
|
return window;
|
|
}
|