mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
Network stack is now configurable, and resolution is also configurable, but loading cursors causes a page-fault?
This commit is contained in:
parent
9d2b08e06e
commit
d4a16d6031
7 changed files with 160 additions and 34 deletions
3
Base/etc/LookupServer.ini
Normal file
3
Base/etc/LookupServer.ini
Normal file
|
@ -0,0 +1,3 @@
|
|||
[DNS]
|
||||
IPAddress=8.8.8.8
|
||||
|
31
Base/home/anon/WindowManager.ini
Normal file
31
Base/home/anon/WindowManager.ini
Normal file
|
@ -0,0 +1,31 @@
|
|||
[Screen]
|
||||
Width=1920
|
||||
Height=1080
|
||||
|
||||
[Cursor]
|
||||
Arrow=/res/cursors/arrow.png
|
||||
ResizeH=/res/cursors/resize-horizontal.png
|
||||
ResizeV=/res/cursor/resize-vertical.png
|
||||
ResizeDTLBR=/res/cursors/resize-diagonal-tlbr.png
|
||||
ResizeDBLTR=/res/cursors/resize-diagonal-bltr.png
|
||||
IBeam=/res/cursors/i-beam.png
|
||||
Disallowed=/res/cursors/disallowed.png
|
||||
Move=/res/cursors/move.png
|
||||
|
||||
[Colors]
|
||||
Background=50,50,50
|
||||
ActiveWindowBorder=110,34,9
|
||||
ActiveWindowBorder2=244,202,158
|
||||
ActiveWindowTitle=255,255,255
|
||||
|
||||
InactiveWindowBorder=128,128,128
|
||||
InactiveWindowBorder2=192,192,192
|
||||
InactiveWindowTitle=213,208,199
|
||||
|
||||
DraggingWindowBorder=161,50,13
|
||||
DraggingWindowBorder2=250,220,187
|
||||
DraggingWindowTitle=255,255,255
|
||||
|
||||
HighlightWindowBorder=161,13,13
|
||||
HighlightWindowBorder2=250,187,187
|
||||
HighlightWindowTitle=255,255,255
|
|
@ -21,6 +21,12 @@ Retained<CConfigFile> CConfigFile::get_for_app(const String& app_name)
|
|||
return adopt(*new CConfigFile(path));
|
||||
}
|
||||
|
||||
Retained<CConfigFile> CConfigFile::get_for_system(const String& app_name)
|
||||
{
|
||||
auto path = String::format("/etc/%s.ini", app_name.characters());
|
||||
return adopt(*new CConfigFile(path));
|
||||
}
|
||||
|
||||
CConfigFile::CConfigFile(const String& file_name)
|
||||
: m_file_name(file_name)
|
||||
{
|
||||
|
@ -105,6 +111,30 @@ int CConfigFile::read_num_entry(const String& group, const String &key, int defa
|
|||
return value;
|
||||
}
|
||||
|
||||
Color CConfigFile::read_color_entry(const String& group, const String &key, Color default_value) const
|
||||
{
|
||||
if (!has_key(group, key)) {
|
||||
const_cast<CConfigFile&>(*this).write_color_entry(group, key, default_value);
|
||||
return default_value;
|
||||
}
|
||||
|
||||
Vector<String> shades = read_entry(group, key).split(',');
|
||||
bool ok = shades.size() >= 3;
|
||||
Color value;
|
||||
if (shades.size() == 3)
|
||||
value = Color(shades[0].to_uint(ok),
|
||||
shades[1].to_uint(ok),
|
||||
shades[2].to_uint(ok));
|
||||
else
|
||||
value = Color(shades[0].to_uint(ok),
|
||||
shades[1].to_uint(ok),
|
||||
shades[2].to_uint(ok),
|
||||
shades[3].to_uint(ok));
|
||||
if (!ok)
|
||||
return default_value;
|
||||
return value;
|
||||
}
|
||||
|
||||
bool CConfigFile::read_bool_entry(const String& group, const String &key, bool default_value) const
|
||||
{
|
||||
return read_entry(group, key, default_value ? "1" : "0") == "1";
|
||||
|
@ -120,6 +150,13 @@ void CConfigFile::write_num_entry(const String& group, const String& key, int va
|
|||
{
|
||||
write_entry(group, key, String::format("%d", value));
|
||||
}
|
||||
void CConfigFile::write_color_entry(const String& group, const String& key, Color value)
|
||||
{
|
||||
write_entry(group, key, String::format("%d,%d,%d,%d", value.red(),
|
||||
value.green(),
|
||||
value.blue(),
|
||||
value.alpha()));
|
||||
}
|
||||
|
||||
bool CConfigFile::sync()
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <SharedGraphics/Color.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/AKString.h>
|
||||
|
@ -9,6 +10,7 @@
|
|||
class CConfigFile : public Retainable<CConfigFile> {
|
||||
public:
|
||||
static Retained<CConfigFile> get_for_app(const String& app_name);
|
||||
static Retained<CConfigFile> get_for_system(const String& app_name);
|
||||
~CConfigFile();
|
||||
|
||||
bool has_group(const String&) const;
|
||||
|
@ -20,10 +22,12 @@ public:
|
|||
String read_entry(const String& group, const String& key, const String& default_vaule = String()) const;
|
||||
int read_num_entry(const String& group, const String& key, int default_value = 0) const;
|
||||
bool read_bool_entry(const String& group, const String& key, bool default_value = false) const;
|
||||
Color read_color_entry(const String& group, const String &key, Color default_value) const;
|
||||
|
||||
void write_entry(const String& group, const String& key, const String &value);
|
||||
void write_num_entry(const String& group, const String& key, int value);
|
||||
void write_bool_entry(const String& group, const String& key, bool value);
|
||||
void write_color_entry(const String& group, const String& key, Color value);
|
||||
|
||||
void dump() const;
|
||||
|
||||
|
@ -34,6 +38,8 @@ public:
|
|||
void remove_group(const String& group);
|
||||
void remove_entry(const String& group, const String& key);
|
||||
|
||||
String file_name() const { return m_file_name; }
|
||||
|
||||
private:
|
||||
explicit CConfigFile(const String& file_name);
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#define C_IN 1
|
||||
|
||||
static Vector<IPv4Address> lookup(const String& hostname, bool& did_timeout);
|
||||
static Vector<IPv4Address> lookup(const String& hostname, bool& did_timeout, const String& DNS_IP);
|
||||
static String parse_dns_name(const byte*, int& offset, int max_offset);
|
||||
|
||||
int main(int argc, char**argv)
|
||||
|
@ -33,6 +33,11 @@ int main(int argc, char**argv)
|
|||
|
||||
unlink("/tmp/.LookupServer-socket");
|
||||
|
||||
auto config = CConfigFile::get_for_system("LookupServer");
|
||||
dbgprintf("LookupServer: Using network config file at %s.\n",
|
||||
config->file_name().view().characters());
|
||||
const String& DNS_IP = config->read_entry("DNS", "IPAddress", "127.0.0.53");
|
||||
|
||||
HashMap<String, IPv4Address> dns_cache;
|
||||
|
||||
int server_fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
||||
|
@ -93,7 +98,9 @@ int main(int argc, char**argv)
|
|||
client_buffer[nrecv] = '\0';
|
||||
|
||||
auto hostname = String(client_buffer, nrecv, Chomp);
|
||||
dbgprintf("LookupServer: Got request for '%s'\n", hostname.characters());
|
||||
dbgprintf("LookupServer: Got request for '%s' (using IP %s)\n",
|
||||
hostname.characters(),
|
||||
DNS_IP.view().characters());
|
||||
|
||||
Vector<IPv4Address> addresses;
|
||||
|
||||
|
@ -102,7 +109,7 @@ int main(int argc, char**argv)
|
|||
int retries = 3;
|
||||
do {
|
||||
did_timeout = false;
|
||||
addresses = lookup(hostname, did_timeout);
|
||||
addresses = lookup(hostname, did_timeout, DNS_IP);
|
||||
if (!did_timeout)
|
||||
break;
|
||||
} while (--retries);
|
||||
|
@ -139,7 +146,7 @@ static word get_next_id()
|
|||
return ++s_next_id;
|
||||
}
|
||||
|
||||
Vector<IPv4Address> lookup(const String& hostname, bool& did_timeout)
|
||||
Vector<IPv4Address> lookup(const String& hostname, bool& did_timeout, const String& DNS_IP)
|
||||
{
|
||||
// FIXME: First check if it's an IP address in a string!
|
||||
|
||||
|
@ -186,7 +193,7 @@ Vector<IPv4Address> lookup(const String& hostname, bool& did_timeout)
|
|||
|
||||
dst_addr.sin_family = AF_INET;
|
||||
dst_addr.sin_port = htons(53);
|
||||
rc = inet_pton(AF_INET, "127.0.0.53", &dst_addr.sin_addr);
|
||||
rc = inet_pton(AF_INET, DNS_IP.view().characters(), &dst_addr.sin_addr);
|
||||
|
||||
int nsent = sendto(fd, buffer.pointer(), buffer.size(), 0,(const struct sockaddr *)&dst_addr, sizeof(dst_addr));
|
||||
if (nsent < 0) {
|
||||
|
|
|
@ -38,28 +38,7 @@ WSWindowManager::WSWindowManager()
|
|||
{
|
||||
s_the = this;
|
||||
|
||||
m_arrow_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/arrow.png"), { 2, 2 });
|
||||
m_resize_horizontally_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/resize-horizontal.png"));
|
||||
m_resize_vertically_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/resize-vertical.png"));
|
||||
m_resize_diagonally_tlbr_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/resize-diagonal-tlbr.png"));
|
||||
m_resize_diagonally_bltr_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/resize-diagonal-bltr.png"));
|
||||
m_i_beam_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/i-beam.png"));
|
||||
m_disallowed_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/disallowed.png"));
|
||||
m_move_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/move.png"));
|
||||
|
||||
m_background_color = Color(50, 50, 50);
|
||||
m_active_window_border_color = Color(110, 34, 9);
|
||||
m_active_window_border_color2 = Color(244, 202, 158);
|
||||
m_active_window_title_color = Color::White;
|
||||
m_inactive_window_border_color = Color(128, 128, 128);
|
||||
m_inactive_window_border_color2 = Color(192, 192, 192);
|
||||
m_inactive_window_title_color = Color(213, 208, 199);
|
||||
m_dragging_window_border_color = Color(161, 50, 13);
|
||||
m_dragging_window_border_color2 = Color(250, 220, 187);
|
||||
m_dragging_window_title_color = Color::White;
|
||||
m_highlight_window_border_color = Color::from_rgb(0xa10d0d);
|
||||
m_highlight_window_border_color2 = Color::from_rgb(0xfabbbb);
|
||||
m_highlight_window_title_color = Color::White;
|
||||
m_wm_config = CConfigFile::get_for_app("WindowManager");
|
||||
|
||||
m_username = getlogin();
|
||||
|
||||
|
@ -103,13 +82,27 @@ WSWindowManager::WSWindowManager()
|
|||
}
|
||||
}
|
||||
switch (item.identifier()) {
|
||||
case 100: set_resolution(640, 480); break;
|
||||
case 101: set_resolution(800, 600); break;
|
||||
case 102: set_resolution(1024, 768); break;
|
||||
case 103: set_resolution(1280, 720); break;
|
||||
case 104: set_resolution(1440, 900); break;
|
||||
case 105: set_resolution(1920, 1080); break;
|
||||
case 106: set_resolution(2560, 1440); break;
|
||||
case 100:
|
||||
set_resolution(640, 480);
|
||||
break;
|
||||
case 101:
|
||||
set_resolution(800, 600);
|
||||
break;
|
||||
case 102:
|
||||
set_resolution(1024, 768);
|
||||
break;
|
||||
case 103:
|
||||
set_resolution(1280, 720);
|
||||
break;
|
||||
case 104:
|
||||
set_resolution(1440, 900);
|
||||
break;
|
||||
case 105:
|
||||
set_resolution(1920, 1080);
|
||||
break;
|
||||
case 106:
|
||||
set_resolution(2560, 1440);
|
||||
break;
|
||||
}
|
||||
if (item.identifier() == 200) {
|
||||
if (fork() == 0) {
|
||||
|
@ -124,6 +117,44 @@ WSWindowManager::WSWindowManager()
|
|||
};
|
||||
}
|
||||
|
||||
dbgprintf("WindowManager: Loaded config from %s\n",
|
||||
m_wm_config->file_name().view().characters());
|
||||
dbgprintf("WindowManager: Screen size is %dx%d\n",
|
||||
m_wm_config->read_num_entry("Screen", "Width", 800),
|
||||
m_wm_config->read_num_entry("Screen", "Height", 600));
|
||||
set_resolution(m_wm_config->read_num_entry("Screen", "Width", 800),
|
||||
m_wm_config->read_num_entry("Screen", "Height", 600));
|
||||
|
||||
dbgprintf("WindowManager: Loading cursors (arrow: %s)\n", m_wm_config->read_entry("Cursor", "Arrow", "").characters());
|
||||
m_arrow_cursor = WSCursor::create(*GraphicsBitmap::load_from_file(m_wm_config->read_entry("Cursor", "Arrow", "")), { 2, 2 });
|
||||
m_resize_horizontally_cursor = WSCursor::create(*GraphicsBitmap::load_from_file(m_wm_config->read_entry("Cursor", "ResizeH", "")));
|
||||
m_resize_vertically_cursor = WSCursor::create(*GraphicsBitmap::load_from_file(m_wm_config->read_entry("Cursor", "ResizeV", "")));
|
||||
m_resize_diagonally_tlbr_cursor = WSCursor::create(*GraphicsBitmap::load_from_file(m_wm_config->read_entry("Cursor", "ResizeDTLBR", "")));
|
||||
m_resize_diagonally_bltr_cursor = WSCursor::create(*GraphicsBitmap::load_from_file(m_wm_config->read_entry("Cursor", "ResizeDBLTR", "")));
|
||||
m_i_beam_cursor = WSCursor::create(*GraphicsBitmap::load_from_file(m_wm_config->read_entry("Cursor", "IBeam", "")));
|
||||
m_disallowed_cursor = WSCursor::create(*GraphicsBitmap::load_from_file(m_wm_config->read_entry("Cursor", "Disallowed", "")));
|
||||
m_move_cursor = WSCursor::create(*GraphicsBitmap::load_from_file(m_wm_config->read_entry("Cursor", "Move", "")));
|
||||
|
||||
dbgprintf("WindowManager: Loading colors\n");
|
||||
m_background_color = m_wm_config->read_color_entry("Colors", "Background", Color::Red);
|
||||
dbgprintf("-- BGColor: %s\n", m_background_color.to_string());
|
||||
|
||||
m_active_window_border_color = m_wm_config->read_color_entry("Colors", "ActiveWindowBorder", Color::Red);
|
||||
m_active_window_border_color2 = m_wm_config->read_color_entry("Colors", "ActiveWindowBorder2", Color::Red);
|
||||
m_active_window_title_color = m_wm_config->read_color_entry("Colors", "ActiveWindowTitle", Color::Red);
|
||||
|
||||
m_inactive_window_border_color = m_wm_config->read_color_entry("Colors", "InactiveWindowBorder", Color::Red);
|
||||
m_inactive_window_border_color2 = m_wm_config->read_color_entry("Colors", "InactiveWindowBorder2", Color::Red);
|
||||
m_inactive_window_title_color = m_wm_config->read_color_entry("Colors", "InactiveWindowTitle", Color::Red);
|
||||
|
||||
m_dragging_window_border_color = m_wm_config->read_color_entry("Colors", "DraggingWindowBorder", Color::Red);
|
||||
m_dragging_window_border_color2 = m_wm_config->read_color_entry("Colors", "DraggingWindowBorder2", Color::Red);
|
||||
m_dragging_window_title_color = m_wm_config->read_color_entry("Colors", "DraggingWindowTitle", Color::Red);
|
||||
|
||||
m_highlight_window_border_color = m_wm_config->read_color_entry("Colors", "HighlightWindowBorder", Color::Red);
|
||||
m_highlight_window_border_color2 = m_wm_config->read_color_entry("Colors", "HighlightWindowBorder2", Color::Red);
|
||||
m_highlight_window_title_color = m_wm_config->read_color_entry("Colors", "HighlightWindowTitle", Color::Red);
|
||||
|
||||
// NOTE: This ensures that the system menu has the correct dimensions.
|
||||
set_current_menubar(nullptr);
|
||||
|
||||
|
@ -176,6 +207,11 @@ void WSWindowManager::set_resolution(int width, int height)
|
|||
WSClientConnection::for_each_client([&] (WSClientConnection& client) {
|
||||
client.notify_about_new_screen_rect(WSScreen::the().rect());
|
||||
});
|
||||
/*dbgprintf("Saving resolution: %dx%d to config file at %s.\n", width, height,
|
||||
m_wm_config->file_name().characters());
|
||||
m_wm_config->write_num_entry("Screen", "Width", width);
|
||||
m_wm_config->write_num_entry("Screen", "Height", height);
|
||||
m_wm_config->sync();*/
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <WindowServer/WSEvent.h>
|
||||
#include <WindowServer/WSCPUMonitor.h>
|
||||
#include <LibCore/CElapsedTimer.h>
|
||||
#include <LibCore/CConfigFile.h>
|
||||
|
||||
class WSAPIClientRequest;
|
||||
class WSScreen;
|
||||
|
@ -40,6 +41,9 @@ public:
|
|||
WSWindowManager();
|
||||
virtual ~WSWindowManager() override;
|
||||
|
||||
RetainPtr<CConfigFile> wm_config() const { return m_wm_config; }
|
||||
void set_wm_config(Retained<CConfigFile> conf) { m_wm_config = conf; }
|
||||
|
||||
void add_window(WSWindow&);
|
||||
void remove_window(WSWindow&);
|
||||
|
||||
|
@ -223,6 +227,8 @@ private:
|
|||
WeakPtr<WSButton> m_hovered_button;
|
||||
|
||||
WSCPUMonitor m_cpu_monitor;
|
||||
|
||||
RetainPtr<CConfigFile> m_wm_config;
|
||||
};
|
||||
|
||||
template<typename Callback>
|
||||
|
|
Loading…
Add table
Reference in a new issue