Skip to content

Commit 0dab2c5

Browse files
committed
Focus handling, taskbar fixes
1 parent ae79f76 commit 0dab2c5

33 files changed

+466
-227
lines changed

applications/desktop/src/background.cpp

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
#include <cairo/cairo.h>
2323
#include <stdlib.h>
2424

25-
background* background::create()
25+
background_t* background_t::create()
2626
{
27-
auto instance = createCanvasComponent<background>();
27+
auto instance = createCanvasComponent<background_t>();
2828
instance->init();
2929
return instance;
3030
}
3131

32-
void background::init()
32+
void background_t::init()
3333
{
34-
organizer = new item_organizer(100, 100, 5, 5);
34+
organizer = new item_organizer_t(100, 100, 5, 5);
3535

3636
this->setBufferListener([this]()
3737
{
@@ -67,7 +67,7 @@ void background::init()
6767
this->organize();
6868
}
6969

70-
void background::onMouseMove(const g_point& position)
70+
void background_t::onMouseMove(const g_point& position)
7171
{
7272
for(auto item: items)
7373
{
@@ -80,9 +80,9 @@ void background::onMouseMove(const g_point& position)
8080
}
8181
}
8282

83-
void background::onMouseLeftPress(const g_point& position, int clickCount)
83+
void background_t::onMouseLeftPress(const g_point& position, int clickCount)
8484
{
85-
item* pressedItem = nullptr;
85+
item_t* pressedItem = nullptr;
8686
std::vector<g_rectangle> itemsBounds;
8787
for(auto& item: items)
8888
{
@@ -107,11 +107,16 @@ void background::onMouseLeftPress(const g_point& position, int clickCount)
107107
{
108108
for(auto& item: items)
109109
{
110+
auto wasSelected = item->selected;
110111
item->selected = false;
111-
item->paint();
112+
if(wasSelected != item->selected)
113+
item->paint();
112114
}
115+
116+
auto wasSelected = pressedItem->selected;
113117
pressedItem->selected = true;
114-
pressedItem->paint();
118+
if(wasSelected != pressedItem->selected)
119+
pressedItem->paint();
115120
}
116121

117122
// Store for each selected item the offset in relation to press point
@@ -129,15 +134,17 @@ void background::onMouseLeftPress(const g_point& position, int clickCount)
129134
{
130135
for(auto item: items)
131136
{
137+
auto wasSelected = item->selected;
132138
item->selected = false;
133-
item->paint();
139+
if(wasSelected != item->selected)
140+
item->paint();
134141
}
135142

136143
selectionStart = position;
137144
}
138145
}
139146

140-
void background::onMouseDrag(const g_point& position)
147+
void background_t::onMouseDrag(const g_point& position)
141148
{
142149
if(dragItems)
143150
{
@@ -163,32 +170,43 @@ void background::onMouseDrag(const g_point& position)
163170
g_rectangle rect = item->getBounds();
164171
if(boundsNorm.intersects(rect))
165172
{
173+
auto wasSelected = item->selected;
166174
item->selected = true;
167-
item->paint();
175+
if(wasSelected != item->selected)
176+
item->paint();
168177
}
169178
else
170179
{
180+
auto wasSelected = item->selected;
171181
item->selected = false;
172-
item->paint();
182+
if(wasSelected != item->selected)
183+
item->paint();
173184
}
174185
}
175186
}
176187
}
177188

178-
void background::onMouseRelease(const g_point& position)
189+
void background_t::onMouseRelease(const g_point& position)
179190
{
180191
if(dragItems)
181192
dragItems = false;
182193
selection->setVisible(false);
183194
organize();
184195
}
185196

186-
void background::organize()
197+
void background_t::organize()
187198
{
188199
this->organizer->organize(items, this->getBounds());
189200
}
190201

191-
void background::paint()
202+
void background_t::addTaskbar(taskbar_t* taskbar)
203+
{
204+
this->taskbar = taskbar;
205+
this->addChild(taskbar);
206+
}
207+
208+
209+
void background_t::paint()
192210
{
193211
auto cr = this->acquireGraphics();
194212
if(!cr)
@@ -199,7 +217,7 @@ void background::paint()
199217
auto bounds = this->getBounds();
200218

201219
srand(g_millis());
202-
int r = rand() % 128 + 50;
220+
static int r = rand() % 128 + 50;
203221

204222
cairo_pattern_t* gradient = cairo_pattern_create_linear(bounds.width * 0.4, 0, bounds.width * 0.8,
205223
bounds.height);
@@ -223,7 +241,7 @@ void background::paint()
223241
this->releaseGraphics();
224242
}
225243

226-
void background::addItem(item* item)
244+
void background_t::addItem(item_t* item)
227245
{
228246
items.push_back(item);
229247
this->addChild(item);

applications/desktop/src/background.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,47 @@
2121
#ifndef DESKTOP_BACKGROUND
2222
#define DESKTOP_BACKGROUND
2323

24+
#include <taskbar.hpp>
25+
2426
#include "item.hpp"
2527
#include "item_organizer.hpp"
2628

2729
#include <libwindow/canvas.hpp>
2830
#include <libwindow/selection.hpp>
2931
#include <vector>
3032

31-
class background : virtual public g_canvas
33+
class background_t : virtual public g_canvas
3234
{
3335
protected:
3436
void init();
3537

36-
std::vector<item*> items;
38+
taskbar_t* taskbar;
39+
std::vector<item_t*> items;
3740
void onMouseMove(const g_point& position);
3841
bool dragItems;
3942
g_point selectionStart;
4043
g_selection* selection = nullptr;
41-
item_organizer* organizer = nullptr;
44+
item_organizer_t* organizer = nullptr;
4245

4346
void onMouseLeftPress(const g_point& position, int clickCount);
4447
void onMouseDrag(const g_point& position);
4548
void onMouseRelease(const g_point& position);
4649

4750
public:
48-
explicit background(g_ui_component_id id):
51+
explicit background_t(g_ui_component_id id):
4952
g_component(id),
5053
g_canvas(id), dragItems(false)
5154
{
5255
}
5356

54-
~background() override = default;
55-
static background* create();
57+
~background_t() override = default;
58+
static background_t* create();
5659

60+
void addTaskbar(taskbar_t* taskbar);
5761
virtual void paint();
5862

5963
void organize();
60-
void addItem(item* item);
64+
void addItem(item_t* item);
6165
};
6266

6367
#endif

applications/desktop/src/desktop.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
#define USER_DESKTOP_DIR "/user/desktop/"
2929

30-
background* background = nullptr;
31-
taskbar* taskbar = nullptr;
30+
background_t* background = nullptr;
31+
taskbar_t* taskbar = nullptr;
3232

3333
int main()
3434
{
@@ -38,14 +38,14 @@ int main()
3838
return -1;
3939
}
4040

41-
background = background::create();
41+
background = background_t::create();
4242
g_ui::registerDesktopCanvas(background);
4343

4444
g_dimension screenDimension;
4545
g_ui::getScreenDimension(screenDimension);
46-
taskbar = taskbar::create();
46+
taskbar = taskbar_t::create();
4747
taskbar->setBounds(g_rectangle(0, screenDimension.height - 40, screenDimension.width, 40));
48-
background->addChild(taskbar);
48+
background->addTaskbar(taskbar);
4949
background->setDesktopListener([](g_ui_windows_event* event)
5050
{
5151
taskbar->handleDesktopEvent(event);
@@ -73,7 +73,7 @@ void desktopLoadItems()
7373
g_properties_parser parser(cfg);
7474
auto properties = parser.getProperties();
7575

76-
auto item = item::create(properties["name"], properties["icon"], properties["application"]);
76+
auto item = item_t::create(properties["name"], properties["icon"], properties["application"]);
7777
background->addItem(item);
7878
item->setBounds(g_rectangle(0, next++ * 100, 100, 100));
7979
}

applications/desktop/src/item.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <libwindow/color_argb.hpp>
2626
#include <helper.hpp>
2727

28-
item::item(uint32_t id):
28+
item_t::item_t(uint32_t id):
2929
g_component(id),
3030
g_canvas(id)
3131
{
@@ -35,14 +35,14 @@ item::item(uint32_t id):
3535
});
3636
}
3737

38-
item* item::create(std::string name, std::string icon, std::string application)
38+
item_t* item_t::create(std::string name, std::string icon, std::string application)
3939
{
40-
auto instance = createCanvasComponent<item>();
40+
auto instance = createCanvasComponent<item_t>();
4141
instance->init(name, icon, application);
4242
return instance;
4343
}
4444

45-
void item::init(std::string name, std::string icon, std::string application)
45+
void item_t::init(std::string name, std::string icon, std::string application)
4646
{
4747
this->application = application;
4848
iconSurface = cairo_image_surface_create_from_png(icon.c_str());
@@ -60,7 +60,7 @@ void item::init(std::string name, std::string icon, std::string application)
6060
this->addChild(label);
6161
}
6262

63-
void item::paint()
63+
void item_t::paint()
6464
{
6565
auto cr = this->acquireGraphics();
6666
if(!cr)
@@ -99,7 +99,7 @@ void item::paint()
9999
this->blit(g_rectangle(0, 0, bounds.width, bounds.height));
100100
}
101101

102-
void item::onDoubleClick()
102+
void item_t::onDoubleClick()
103103
{
104104
klog(("Launching: " + this->application).c_str());
105105
g_spawn(this->application.c_str(), "", "", G_SECURITY_LEVEL_APPLICATION);

applications/desktop/src/item.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <libwindow/label.hpp>
2626
#include <cairo/cairo.h>
2727

28-
class item : virtual public g_canvas
28+
class item_t : virtual public g_canvas
2929
{
3030
protected:
3131
cairo_surface_t* iconSurface = nullptr;
@@ -35,15 +35,15 @@ class item : virtual public g_canvas
3535
void init(std::string name, std::string icon, std::string application);
3636

3737
public:
38-
explicit item(uint32_t id);
38+
explicit item_t(uint32_t id);
3939

4040
bool hover = false;
4141
bool selected = false;
4242
g_point dragOffset;
4343

44-
static item* create(std::string name, std::string icon, std::string application);
44+
static item_t* create(std::string name, std::string icon, std::string application);
4545

46-
~item() override = default;
46+
~item_t() override = default;
4747
virtual void paint();
4848
void onDoubleClick();
4949
};

applications/desktop/src/item_organizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include "item_organizer.hpp"
2323

24-
void item_organizer::organize(const std::vector<item*>& items, const g_rectangle& backgroundBounds) const
24+
void item_organizer_t::organize(const std::vector<item_t*>& items, const g_rectangle& backgroundBounds) const
2525
{
2626
std::vector<g_rectangle> allBounds;
2727
for(auto& item: items)

applications/desktop/src/item_organizer.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include <vector>
2828

29-
class item_organizer
29+
class item_organizer_t
3030
{
3131
struct
3232
{
@@ -37,12 +37,12 @@ class item_organizer
3737
} grid;
3838

3939
public:
40-
item_organizer(int cellWidth, int cellHeight, int xPadding, int yPadding) :
40+
item_organizer_t(int cellWidth, int cellHeight, int xPadding, int yPadding) :
4141
grid{cellWidth, cellHeight, xPadding, yPadding}
4242
{
4343
}
4444

45-
void organize(const std::vector<item*>& items, const g_rectangle& backgroundBounds) const;
45+
void organize(const std::vector<item_t*>& items, const g_rectangle& backgroundBounds) const;
4646
};
4747

4848

0 commit comments

Comments
 (0)