Skip to content

Commit 297505b

Browse files
committed
Window server bugfixes, reduce overhead, fix blitting error; begin tree view & text area implementation
1 parent 753883f commit 297505b

30 files changed

+1367
-305
lines changed

applications/applications.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ with SRC "src"
2525
with OBJ "obj"
2626
with LDFLAGS ""
2727
with CFLAGS_ADD ""
28-
with CFLAGS "-std=c++11 -I$SRC $CFLAGS_ADD"
28+
with CFLAGS "-std=c++17 -I$SRC $CFLAGS_ADD"
2929

3030
with ARTIFACT_LOCAL "$OBJ/$ARTIFACT_NAME"
3131
with ARTIFACT_LOCAL_STATIC "$OBJ/$ARTIFACT_NAME_STATIC"

applications/libraries.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ with ARTIFACT_LOCAL_SHARED "$ARTIFACT_NAME_SHARED"
3232
with ARTIFACT_TARGET_SHARED "$SYSROOT_SYSTEM_LIB/$ARTIFACT_NAME_SHARED"
3333

3434
with CFLAGS_ADD ""
35-
with CFLAGS "-std=c++11 -I$INC $CFLAGS_ADD"
35+
with CFLAGS "-std=c++17 -I$INC $CFLAGS_ADD"
3636
with LDFLAGS "-shared"
3737

3838
# Targets

applications/libwindow/inc/libwindow/button.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#include "component.hpp"
2626
#include "titled_component.hpp"
2727

28+
typedef uint8_t g_button_style;
29+
#define G_BUTTON_STYLE_DEFAULT 0
30+
#define G_BUTTON_STYLE_GHOST 1
31+
2832
class g_button : virtual public g_component, virtual public g_titled_component, virtual public g_action_component
2933
{
3034
public:
@@ -36,6 +40,9 @@ class g_button : virtual public g_component, virtual public g_titled_component,
3640

3741
void setEnabled(bool enabled);
3842
bool isEnabled();
43+
44+
void setStyle(g_button_style style);
45+
g_button_style getStyle();
3946
};
4047

4148
#endif

applications/libwindow/inc/libwindow/interface.hpp

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
*/
3939
#define G_UI_MAXIMUM_MESSAGE_SIZE 4096
4040

41-
#define G_UI_STRING_PROPERTY_MAXIMUM 1024
4241
#define G_UI_COMPONENT_TITLE_MAXIMUM 1024
4342

4443
/**
@@ -63,8 +62,7 @@ typedef uint8_t g_ui_protocol_command_id;
6362
#define G_UI_PROTOCOL_INITIALIZATION ((g_ui_protocol_command_id) 1)
6463
#define G_UI_PROTOCOL_CREATE_COMPONENT ((g_ui_protocol_command_id) 2)
6564
#define G_UI_PROTOCOL_ADD_COMPONENT ((g_ui_protocol_command_id) 3)
66-
#define G_UI_PROTOCOL_SET_TITLE ((g_ui_protocol_command_id) 4)
67-
#define G_UI_PROTOCOL_GET_TITLE ((g_ui_protocol_command_id) 5)
65+
6866
#define G_UI_PROTOCOL_SET_BOUNDS ((g_ui_protocol_command_id) 6)
6967
#define G_UI_PROTOCOL_FOCUS ((g_ui_protocol_command_id) 7)
7068
#define G_UI_PROTOCOL_ADD_LISTENER ((g_ui_protocol_command_id) 8)
@@ -268,38 +266,6 @@ typedef struct
268266
g_rectangle bounds;
269267
} __attribute__((packed)) g_ui_component_get_bounds_response;
270268

271-
/**
272-
* Request/response for setting the title on a titled component
273-
*/
274-
typedef struct
275-
{
276-
g_ui_message_header header;
277-
g_ui_component_id id;
278-
char title[G_UI_COMPONENT_TITLE_MAXIMUM];
279-
} __attribute__((packed)) g_ui_component_set_title_request;
280-
281-
typedef struct
282-
{
283-
g_ui_message_header header;
284-
g_ui_protocol_status status;
285-
} __attribute__((packed)) g_ui_component_set_title_response;
286-
287-
/**
288-
* Request/response for getting the title on a titled component
289-
*/
290-
typedef struct
291-
{
292-
g_ui_message_header header;
293-
g_ui_component_id id;
294-
} __attribute__((packed)) g_ui_component_get_title_request;
295-
296-
typedef struct
297-
{
298-
g_ui_message_header header;
299-
g_ui_protocol_status status;
300-
char title[G_UI_COMPONENT_TITLE_MAXIMUM];
301-
} __attribute__((packed)) g_ui_component_get_title_response;
302-
303269
/**
304270
* Request/response for getting a numeric property
305271
*/
@@ -342,7 +308,7 @@ typedef struct
342308
g_ui_message_header header;
343309
g_ui_component_id id;
344310
int property;
345-
char value[G_UI_STRING_PROPERTY_MAXIMUM];
311+
char value[];
346312
} __attribute__((packed)) g_ui_component_set_string_property_request;
347313

348314
/**
@@ -359,7 +325,7 @@ typedef struct
359325
{
360326
g_ui_message_header header;
361327
g_ui_protocol_status status;
362-
char value[G_UI_STRING_PROPERTY_MAXIMUM];
328+
char value[];
363329
} __attribute__((packed)) g_ui_component_get_string_property_response;
364330

365331
/**

applications/libwindow/inc/libwindow/properties.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,7 @@
4040
#define G_UI_PROPERTY_DISPATCHES_FOCUS 12
4141
#define G_UI_PROPERTY_FLEX_GAP 13
4242
#define G_UI_PROPERTY_IMAGE_SOURCE 14
43+
#define G_UI_PROPERTY_STYLE 15
44+
#define G_UI_PROPERTY_TITLE 16
4345

4446
#endif

applications/libwindow/src/button.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,17 @@ bool g_button::isEnabled()
3838
getNumericProperty(G_UI_PROPERTY_ENABLED, &value);
3939
return value;
4040
}
41+
42+
void g_button::setStyle(g_button_style style)
43+
{
44+
setNumericProperty(G_UI_PROPERTY_STYLE, style);
45+
}
46+
47+
g_button_style g_button::getStyle()
48+
{
49+
uint32_t value;
50+
getNumericProperty(G_UI_PROPERTY_STYLE, &value);
51+
return value;
52+
}
53+
54+

applications/libwindow/src/component.cpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <utility>
2525
#include <cstring>
26+
#include <malloc.h>
2627

2728
g_component::~g_component()
2829
{
@@ -201,21 +202,24 @@ bool g_component::setStringProperty(int property, std::string value)
201202

202203
g_message_transaction tx = g_get_message_tx_id();
203204

204-
auto request = new g_ui_component_set_string_property_request();
205+
auto requestSize = sizeof(g_ui_component_set_string_property_request) + value.length() + 1;
206+
auto request = static_cast<g_ui_component_set_string_property_request*>(
207+
operator new(sizeof(g_ui_component_set_string_property_request) + value.length() + 1)
208+
);
205209
request->header.id = G_UI_PROTOCOL_SET_STRING_PROPERTY;
206210
request->id = this->id;
207211
request->property = property;
208-
strncpy(request->value, value.c_str(), G_UI_STRING_PROPERTY_MAXIMUM - 1);
212+
strcpy(request->value, value.c_str());
209213

210-
g_send_message_t(g_ui_delegate_tid, request, sizeof(g_ui_component_set_string_property_request), tx);
214+
g_send_message_t(g_ui_delegate_tid, request, requestSize, tx);
211215
g_yield_t(g_ui_delegate_tid);
212216

213-
size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_simple_response);
214-
uint8_t buffer[bufferSize];
217+
size_t responseBufferSize = sizeof(g_message_header) + sizeof(g_ui_simple_response);
218+
uint8_t responseBuffer[responseBufferSize];
215219
bool success = false;
216-
if(g_receive_message_t(buffer, bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
220+
if(g_receive_message_t(responseBuffer, responseBufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
217221
{
218-
auto response = (g_ui_simple_response*) G_MESSAGE_CONTENT(buffer);
222+
auto response = (g_ui_simple_response*) G_MESSAGE_CONTENT(responseBuffer);
219223
success = (response->status == G_UI_PROTOCOL_SUCCESS);
220224
}
221225

@@ -237,20 +241,26 @@ bool g_component::getStringProperty(int property, std::string& out)
237241
g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_component_get_string_property_request), tx);
238242
g_yield_t(g_ui_delegate_tid);
239243

240-
size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_component_get_string_property_response);
241-
auto buffer = new uint8_t[bufferSize];
242244
bool success = false;
243-
if(g_receive_message_t(buffer, bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
245+
for(int size = 128; size <= 1024; size *= 2)
244246
{
245-
auto response = (g_ui_component_get_string_property_response*) G_MESSAGE_CONTENT(buffer);
246-
if(response->status == G_UI_PROTOCOL_SUCCESS)
247+
size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_component_get_string_property_response) + size;
248+
auto buffer = new uint8_t[bufferSize];
249+
auto receiveStatus = g_receive_message_t(buffer, bufferSize, tx);
250+
if(receiveStatus == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
247251
{
248-
success = true;
249-
out = std::string(response->value);
252+
auto response = (g_ui_component_get_string_property_response*) G_MESSAGE_CONTENT(buffer);
253+
if(response->status == G_UI_PROTOCOL_SUCCESS)
254+
{
255+
success = true;
256+
out = std::string(response->value);
257+
}
250258
}
251-
}
259+
delete buffer;
252260

253-
delete buffer;
261+
if(success || receiveStatus != G_MESSAGE_RECEIVE_STATUS_EXCEEDS_BUFFER_SIZE)
262+
break;
263+
}
254264
return success;
255265
}
256266

applications/libwindow/src/titled_component.cpp

Lines changed: 5 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -18,87 +18,22 @@
1818
* *
1919
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2020

21-
#include <cstring>
2221
#include <utility>
2322

2423
#include "libwindow/titled_component.hpp"
25-
#include "libwindow/ui.hpp"
2624
#include "libwindow/listener/title_listener.hpp"
25+
#include "libwindow/properties.hpp"
2726

2827
bool g_titled_component::setTitle(std::string title)
2928
{
30-
if(!g_ui_initialized)
31-
return false;
32-
33-
// send initialization request
34-
g_message_transaction tx = g_get_message_tx_id();
35-
36-
auto request = new g_ui_component_set_title_request();
37-
request->header.id = G_UI_PROTOCOL_SET_TITLE;
38-
request->id = this->id;
39-
40-
// fill text (truncate if necessary)
41-
const char* title_str = title.c_str();
42-
size_t title_len;
43-
if(title.length() >= G_UI_COMPONENT_TITLE_MAXIMUM)
44-
{
45-
title_len = G_UI_COMPONENT_TITLE_MAXIMUM;
46-
}
47-
else
48-
{
49-
title_len = title.length();
50-
}
51-
memcpy(request->title, title.c_str(), title_len);
52-
request->title[title_len] = 0;
53-
54-
g_send_message_t(g_ui_delegate_tid, request, sizeof(g_ui_component_set_title_request), tx);
55-
g_yield_t(g_ui_delegate_tid);
56-
57-
// read response
58-
size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_component_set_title_response);
59-
uint8_t buffer[bufferSize];
60-
61-
bool success = false;
62-
if(g_receive_message_t(buffer, bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
63-
{
64-
auto response = (g_ui_component_set_title_response*) G_MESSAGE_CONTENT(buffer);
65-
success = (response->status == G_UI_PROTOCOL_SUCCESS);
66-
}
67-
68-
delete request;
69-
return success;
29+
return setStringProperty(G_UI_PROPERTY_TITLE, title);
7030
}
7131

7232
std::string g_titled_component::getTitle()
7333
{
74-
if(!g_ui_initialized)
75-
return "";
76-
77-
// send initialization request
78-
g_message_transaction tx = g_get_message_tx_id();
79-
80-
g_ui_component_get_title_request request;
81-
request.header.id = G_UI_PROTOCOL_GET_TITLE;
82-
request.id = this->id;
83-
g_send_message_t(g_ui_delegate_tid, &request, sizeof(g_ui_component_get_title_request), tx);
84-
g_yield_t(g_ui_delegate_tid);
85-
86-
// read response
87-
size_t bufferSize = sizeof(g_message_header) + sizeof(g_ui_component_get_title_response);
88-
auto buffer = new uint8_t[bufferSize];
89-
90-
std::string title = "";
91-
if(g_receive_message_t(buffer, bufferSize, tx) == G_MESSAGE_RECEIVE_STATUS_SUCCESSFUL)
92-
{
93-
auto response = (g_ui_component_get_title_response*) G_MESSAGE_CONTENT(buffer);
94-
if(response->status == G_UI_PROTOCOL_SUCCESS)
95-
{
96-
title = std::string(response->title);
97-
}
98-
}
99-
100-
delete buffer;
101-
return title;
34+
std::string out;
35+
getStringProperty(G_UI_PROPERTY_TITLE, out);
36+
return out;
10237
}
10338

10439
void g_titled_component::addTitleListener(std::function<void(std::string)> func)

applications/navigator/src/navigator.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ int main()
7676
navBar->setFlexGap(10);
7777
{
7878
navPrev = g_button::create();
79+
navPrev->setStyle(G_BUTTON_STYLE_GHOST);
7980
navPrev->setTitle("<");
8081
navBar->addChild(navPrev);
8182
navBar->setFlexComponentInfo(navPrev, 0, 1, 50);
@@ -90,6 +91,7 @@ int main()
9091
});
9192

9293
navNext = g_button::create();
94+
navNext->setStyle(G_BUTTON_STYLE_GHOST);
9395
navNext->setTitle(">");
9496
navBar->addChild(navNext);
9597
navBar->setFlexComponentInfo(navNext, 0, 1, 50);
@@ -119,6 +121,7 @@ int main()
119121

120122
navUp = g_button::create();
121123
navUp->setTitle("^");
124+
navUp->setStyle(G_BUTTON_STYLE_GHOST);
122125
navBar->addChild(navUp);
123126
navBar->setFlexComponentInfo(navUp, 0, 1, 50);
124127

applications/windowserver/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fi
88
# Build configuration
99
ARTIFACT_NAME="windowserver.bin"
1010
CFLAGS_ADD="-I$SYSROOT_SYSTEM_INCLUDE/freetype2 -msse2"
11-
LDFLAGS="-linput -lvideo -lps2driver -lproperties -lwindow -lfont -lcairo -lfreetype -lpixman-1 -lpng -lz"
11+
LDFLAGS="-ljson -linput -lvideo -lps2driver -lproperties -lwindow -lfont -lcairo -lfreetype -lpixman-1 -lpng -lz"
1212

1313
# Include application build tasks
1414
. "../applications.sh"

0 commit comments

Comments
 (0)