1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:27:45 +00:00

Taskbar: More bringup work. We now see a basic window list.

This commit is contained in:
Andreas Kling 2019-04-04 01:44:35 +02:00
parent ea801a99dc
commit 96104b5524
20 changed files with 339 additions and 12 deletions

View file

@ -1,6 +1,7 @@
OBJS = \
TaskbarWindow.o \
TaskbarWidget.o \
WindowList.o \
main.o
APP = Taskbar

View file

@ -5,13 +5,14 @@
#include <LibGUI/GPainter.h>
#include <stdio.h>
TaskbarWidget::TaskbarWidget(GWidget* parent)
TaskbarWidget::TaskbarWidget(WindowList& window_list, GWidget* parent)
: GFrame(parent)
, m_window_list(window_list)
{
set_fill_with_background_color(true);
set_layout(make<GBoxLayout>(Orientation::Horizontal));
layout()->set_margins({ 0, 8, 0, 8 });
layout()->set_spacing(8);
layout()->set_margins({ 0, 3, 0, 3 });
layout()->set_spacing(3);
set_frame_thickness(1);
set_frame_shape(GFrame::Shape::Panel);

View file

@ -1,8 +1,10 @@
#include <LibGUI/GFrame.h>
class WindowList;
class TaskbarWidget final : public GFrame {
public:
TaskbarWidget(GWidget* parent = nullptr);
TaskbarWidget(WindowList&, GWidget* parent = nullptr);
virtual ~TaskbarWidget() override;
virtual const char* class_name() const override { return "TaskbarWidget"; }
@ -10,4 +12,5 @@ public:
private:
virtual void paint_event(GPaintEvent&) override;
WindowList& m_window_list;
};

View file

@ -3,6 +3,7 @@
#include <LibGUI/GWindow.h>
#include <LibGUI/GDesktop.h>
#include <LibGUI/GEventLoop.h>
#include <LibGUI/GButton.h>
#include <WindowServer/WSAPITypes.h>
#include <stdio.h>
@ -16,7 +17,7 @@ TaskbarWindow::TaskbarWindow()
GDesktop::the().on_rect_change = [this] (const Rect& rect) { on_screen_rect_change(rect); };
auto* widget = new TaskbarWidget;
auto* widget = new TaskbarWidget(m_window_list);
set_main_widget(widget);
}
@ -32,10 +33,51 @@ void TaskbarWindow::on_screen_rect_change(const Rect& rect)
void TaskbarWindow::wm_event(GWMEvent& event)
{
#if 0
WindowIdentifier identifier { event.client_id(), event.window_id() };
switch (event.type()) {
case GEvent::WM_WindowAdded:
m_window_list.append({})
case GEvent::WM_WindowAdded: {
auto& added_event = static_cast<GWMWindowAddedEvent&>(event);
printf("WM_WindowAdded: client_id=%d, window_id=%d, title=%s, rect=%s\n",
added_event.client_id(),
added_event.window_id(),
added_event.title().characters(),
added_event.rect().to_string().characters()
);
auto& window = m_window_list.ensure_window(identifier);
window.set_title(added_event.title());
window.set_rect(added_event.rect());
window.set_button(new GButton(main_widget()));
window.button()->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
window.button()->set_preferred_size({ 100, 22 });
window.button()->set_caption(window.title());
update();
break;
}
case GEvent::WM_WindowRemoved: {
auto& removed_event = static_cast<GWMWindowRemovedEvent&>(event);
printf("WM_WindowRemoved: client_id=%d, window_id=%d\n",
removed_event.client_id(),
removed_event.window_id()
);
m_window_list.remove_window(identifier);
update();
break;
}
case GEvent::WM_WindowStateChanged: {
auto& changed_event = static_cast<GWMWindowStateChangedEvent&>(event);
printf("WM_WindowStateChanged: client_id=%d, window_id=%d, title=%s, rect=%s\n",
changed_event.client_id(),
changed_event.window_id(),
changed_event.title().characters(),
changed_event.rect().to_string().characters()
);
auto& window = m_window_list.ensure_window(identifier);
window.set_title(changed_event.title());
window.set_rect(changed_event.rect());
window.button()->set_caption(changed_event.title());
break;
}
default:
break;
}
#endif
}

View file

@ -1,12 +1,13 @@
#include <LibGUI/GWindow.h>
#include <LibGUI/GWidget.h>
#include "WindowList.h"
class TaskbarWindow final : public GWindow {
public:
TaskbarWindow();
virtual ~TaskbarWindow() override;
int taskbar_height() const { return 20; }
int taskbar_height() const { return 28; }
virtual const char* class_name() const override { return "TaskbarWindow"; }
@ -14,4 +15,6 @@ private:
void on_screen_rect_change(const Rect&);
virtual void wm_event(GWMEvent&) override;
WindowList m_window_list;
};

View file

@ -0,0 +1,17 @@
#include "WindowList.h"
Window& WindowList::ensure_window(const WindowIdentifier& identifier)
{
auto it = m_windows.find(identifier);
if (it != m_windows.end())
return *it->value;
auto window = make<Window>(identifier);
auto& window_ref = *window;
m_windows.set(identifier, move(window));
return window_ref;
}
void WindowList::remove_window(const WindowIdentifier& identifier)
{
m_windows.remove(identifier);
}

View file

@ -0,0 +1,80 @@
#pragma once
#include <AK/AKString.h>
#include <AK/HashMap.h>
#include <AK/Traits.h>
#include <SharedGraphics/Rect.h>
#include <LibGUI/GButton.h>
class WindowIdentifier {
public:
WindowIdentifier(int client_id, int window_id)
: m_client_id(client_id)
, m_window_id(window_id)
{
}
int client_id() const { return m_client_id; }
int window_id() const { return m_window_id; }
bool operator==(const WindowIdentifier& other) const
{
return m_client_id == other.m_client_id && m_window_id == other.m_window_id;
}
private:
int m_client_id { -1 };
int m_window_id { -1 };
};
namespace AK {
template<>
struct Traits<WindowIdentifier> {
static unsigned hash(const WindowIdentifier& w) { return pair_int_hash(w.client_id(), w.window_id()); }
static void dump(const WindowIdentifier& w) { kprintf("WindowIdentifier(%d, %d)", w.client_id(), w.window_id()); }
};
}
class Window {
public:
explicit Window(const WindowIdentifier& identifier)
: m_identifier(identifier)
{
}
~Window()
{
delete m_button;
}
WindowIdentifier identifier() const { return m_identifier; }
String title() const { return m_title; }
void set_title(const String& title) { m_title = title; }
Rect rect() const { return m_rect; }
void set_rect(const Rect& rect) { m_rect = rect; }
GButton* button() { return m_button; }
void set_button(GButton* button) { m_button = button; }
private:
WindowIdentifier m_identifier;
String m_title;
Rect m_rect;
GButton* m_button { nullptr };
};
class WindowList {
public:
template<typename Callback> void for_each_window(Callback callback)
{
for (auto& it : m_windows)
callback(*it.value);
}
Window& ensure_window(const WindowIdentifier&);
void remove_window(const WindowIdentifier&);
private:
HashMap<WindowIdentifier, OwnPtr<Window>> m_windows;
};