From c23882dde1f8a46f82b599ece5bb4b59606d030b Mon Sep 17 00:00:00 2001 From: Christopher Dumas Date: Sun, 26 May 2019 10:14:03 -0700 Subject: [PATCH] can now tile background and made sure the IRC choose server popup still works --- Applications/IRCClient/IRCAppWindow.cpp | 5 +--- Applications/IRCClient/IRCClient.cpp | 7 +++-- Applications/IRCClient/IRCClient.h | 2 +- Base/home/anon/Terminal.ini | 2 +- Base/home/anon/WindowManager.ini | 3 ++ LibCore/CConfigFile.cpp | 30 ++++++++++++-------- LibCore/CUserInfo.cpp | 20 +++++++------- Servers/LookupServer/Makefile | 2 +- Servers/LookupServer/main.cpp | 5 ++-- Servers/WindowServer/WSCompositor.cpp | 26 ++++++++++++++++-- Servers/WindowServer/WSCompositor.h | 3 ++ Servers/WindowServer/WSWindowManager.cpp | 35 ++++++++++++++++++------ Servers/WindowServer/WSWindowManager.h | 3 ++ SharedGraphics/Painter.cpp | 26 ++++++++++++++++++ SharedGraphics/Painter.h | 2 +- 15 files changed, 127 insertions(+), 44 deletions(-) diff --git a/Applications/IRCClient/IRCAppWindow.cpp b/Applications/IRCClient/IRCAppWindow.cpp index c6ebb54226c..ca19133cdda 100644 --- a/Applications/IRCClient/IRCAppWindow.cpp +++ b/Applications/IRCClient/IRCAppWindow.cpp @@ -48,11 +48,8 @@ void IRCAppWindow::setup_client() m_client.on_nickname_changed = [this] (const String&) { update_title(); }; - m_client.on_connect = [this] { - m_client.join_channel("#test"); - }; - if (m_client.hostname() == "none") { + if (m_client.hostname().is_empty()) { GInputBox input_box("Enter server:", "Connect to server", this); auto result = input_box.exec(); if (result == GInputBox::ExecCancel) diff --git a/Applications/IRCClient/IRCClient.cpp b/Applications/IRCClient/IRCClient.cpp index 76a3f16535d..a4e2cdb165f 100644 --- a/Applications/IRCClient/IRCClient.cpp +++ b/Applications/IRCClient/IRCClient.cpp @@ -35,7 +35,7 @@ IRCClient::IRCClient() { m_socket = new CTCPSocket(this); m_nickname = m_config->read_entry("User", "Nickname", "seren1ty"); - m_hostname = m_config->read_entry("Connection", "Server", "chat.freenode.net"); + m_hostname = m_config->read_entry("Connection", "Server", ""); m_port = m_config->read_num_entry("Connection", "Port", 6667); } @@ -47,6 +47,9 @@ void IRCClient::set_server(const String &hostname, int port) { m_hostname = hostname; m_port = port; + m_config->write_entry("Connection", "Server", hostname); + m_config->write_num_entry("Connection", "Port", port); + m_config->sync(); } void IRCClient::on_socket_connected() @@ -61,7 +64,7 @@ void IRCClient::on_socket_connected() auto channel_str = m_config->read_entry("Connection", "AutoJoinChannels", "#test"); dbgprintf("IRCClient: Channels to autojoin: %s\n", channel_str.characters()); auto channels = channel_str.split(','); - for (auto channel : channels) { + for (auto& channel : channels) { join_channel(channel); dbgprintf("IRCClient: Auto joining channel: %s\n", channel.characters()); } diff --git a/Applications/IRCClient/IRCClient.h b/Applications/IRCClient/IRCClient.h index 98fb7664ff4..2ae4c348fad 100644 --- a/Applications/IRCClient/IRCClient.h +++ b/Applications/IRCClient/IRCClient.h @@ -112,7 +112,7 @@ private: void on_socket_connected(); - String m_hostname { "none" }; + String m_hostname; int m_port { 6667 }; CTCPSocket* m_socket { nullptr }; diff --git a/Base/home/anon/Terminal.ini b/Base/home/anon/Terminal.ini index b8edb793016..824c296d395 100644 --- a/Base/home/anon/Terminal.ini +++ b/Base/home/anon/Terminal.ini @@ -1,2 +1,2 @@ [Window] -Opacity=150 +Opacity=255 diff --git a/Base/home/anon/WindowManager.ini b/Base/home/anon/WindowManager.ini index 8efe5831fc4..e142b0c28d1 100644 --- a/Base/home/anon/WindowManager.ini +++ b/Base/home/anon/WindowManager.ini @@ -34,3 +34,6 @@ MenuSelectionColor=132,53,26 [Input] DoubleClickSpeed=250 + +[Background] +Mode=tile diff --git a/LibCore/CConfigFile.cpp b/LibCore/CConfigFile.cpp index e21014783cc..6b462145612 100644 --- a/LibCore/CConfigFile.cpp +++ b/LibCore/CConfigFile.cpp @@ -112,19 +112,25 @@ Color CConfigFile::read_color_entry(const String& group, const String &key, Colo return default_value; } - Vector shades = read_entry(group, key).split(','); - bool ok = shades.size() >= 3; + auto shades = read_entry(group, key).split(','); + if (shades.size() < 3) + return default_value; + bool ok1 = true, + ok2 = true, + ok3 = true, + ok4 = true; 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) + if (shades.size() == 3) { + value = Color(shades[0].to_uint(ok1), + shades[1].to_uint(ok2), + shades[2].to_uint(ok3)); + } else { + value = Color(shades[0].to_uint(ok1), + shades[1].to_uint(ok2), + shades[2].to_uint(ok3), + shades[3].to_uint(ok4)); + } + if (!(ok1 && ok2 && ok3 && ok4)) return default_value; return value; } diff --git a/LibCore/CUserInfo.cpp b/LibCore/CUserInfo.cpp index e297468fee0..9efe1604893 100644 --- a/LibCore/CUserInfo.cpp +++ b/LibCore/CUserInfo.cpp @@ -3,15 +3,15 @@ #include #include -const char *get_current_user_home_path() { - if (auto* home_env = getenv("HOME")) { +const char* get_current_user_home_path() +{ + if (auto* home_env = getenv("HOME")) return home_env; - } else { - auto d = "/"; - uid_t uid = getuid(); - if (auto* pwd = getpwuid(uid)) - return pwd->pw_dir; - else - return d; - } + + auto d = "/"; + uid_t uid = getuid(); + if (auto* pwd = getpwuid(uid)) + return pwd->pw_dir; + + return d; } diff --git a/Servers/LookupServer/Makefile b/Servers/LookupServer/Makefile index b85335b4d5e..da9bb8b7f91 100644 --- a/Servers/LookupServer/Makefile +++ b/Servers/LookupServer/Makefile @@ -11,7 +11,7 @@ DEFINES += -DUSERLAND all: $(APP) $(APP): $(OBJS) - $(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lc + $(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lc -lcore .cpp.o: @echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $< diff --git a/Servers/LookupServer/main.cpp b/Servers/LookupServer/main.cpp index 09637982b3b..2deaf273ea5 100644 --- a/Servers/LookupServer/main.cpp +++ b/Servers/LookupServer/main.cpp @@ -13,6 +13,7 @@ #include #include "DNSPacket.h" #include "DNSRecord.h" +#include #define T_A 1 #define T_NS 2 @@ -35,8 +36,8 @@ int main(int argc, char**argv) 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"); + config->file_name().characters()); + auto DNS_IP = config->read_entry("DNS", "IPAddress", "127.0.0.53"); HashMap dns_cache; diff --git a/Servers/WindowServer/WSCompositor.cpp b/Servers/WindowServer/WSCompositor.cpp index ef2b1fd87e7..069a82b2632 100644 --- a/Servers/WindowServer/WSCompositor.cpp +++ b/Servers/WindowServer/WSCompositor.cpp @@ -16,6 +16,16 @@ WSCompositor& WSCompositor::the() return s_the; } +WallpaperMode mode_to_enum(const String& name) +{ + if (name == "simple") + return WallpaperMode::Simple; + if (name == "tile") + return WallpaperMode::Tile; + if (name == "center") + return WallpaperMode::Center; +} + WSCompositor::WSCompositor() { auto size = WSScreen::the().size(); @@ -49,6 +59,9 @@ WSCompositor::WSCompositor() void WSCompositor::compose() { auto& wm = WSWindowManager::the(); + if (m_wallpaper_mode == WallpaperMode::Unchecked) + m_wallpaper_mode = mode_to_enum(wm.wm_config()->read_entry("Background", "Mode", "simple")); + auto& ws = WSScreen::the(); auto dirty_rects = move(m_dirty_rects); @@ -77,8 +90,17 @@ void WSCompositor::compose() if (wm.any_opaque_window_contains_rect(dirty_rect)) continue; m_back_painter->fill_rect(dirty_rect, wm.m_background_color); - if (m_wallpaper) - m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect); + if (m_wallpaper) { + if (m_wallpaper_mode == WallpaperMode::Simple || + m_wallpaper_mode == WallpaperMode::Unchecked) { + m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect); + } else if (m_wallpaper_mode == WallpaperMode::Center) { + // TODO: Implement centered wallpaper + m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect); + } else if (m_wallpaper_mode == WallpaperMode::Tile) { + m_back_painter->blit_tiled(dirty_rect.location(), *m_wallpaper, dirty_rect); + } + } } auto compose_window = [&] (WSWindow& window) -> IterationDecision { diff --git a/Servers/WindowServer/WSCompositor.h b/Servers/WindowServer/WSCompositor.h index f0ea27bf14e..ea65bd24bf9 100644 --- a/Servers/WindowServer/WSCompositor.h +++ b/Servers/WindowServer/WSCompositor.h @@ -10,6 +10,8 @@ class Painter; class WSCursor; +enum class WallpaperMode { Simple, Tile, Center, Unchecked }; + class WSCompositor final : public CObject { public: static WSCompositor& the(); @@ -55,5 +57,6 @@ private: Rect m_last_geometry_label_rect; String m_wallpaper_path; + WallpaperMode m_wallpaper_mode { WallpaperMode::Unchecked }; RetainPtr m_wallpaper; }; diff --git a/Servers/WindowServer/WSWindowManager.cpp b/Servers/WindowServer/WSWindowManager.cpp index 0a534ab43dd..1c8f594f131 100644 --- a/Servers/WindowServer/WSWindowManager.cpp +++ b/Servers/WindowServer/WSWindowManager.cpp @@ -112,6 +112,25 @@ WSWindowManager::~WSWindowManager() { } +Retained WSWindowManager::get_cursor(const String& name, const Point& hotspot) +{ + auto path = m_wm_config->read_entry("Cursor", name, "/res/cursors/arrow.png"); + auto gb = GraphicsBitmap::load_from_file(path); + if (gb) + return WSCursor::create(*gb, hotspot); + return WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/arrow.png")); +} + +Retained WSWindowManager::get_cursor(const String& name) +{ + auto path = m_wm_config->read_entry("Cursor", name, "/res/cursors/arrow.png"); + auto gb = GraphicsBitmap::load_from_file(path); + + if (gb) + return WSCursor::create(*gb); + return WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/arrow.png")); +} + void WSWindowManager::reload_config(bool set_screen) { m_wm_config = CConfigFile::get_for_app("WindowManager"); @@ -122,14 +141,14 @@ void WSWindowManager::reload_config(bool set_screen) set_resolution(m_wm_config->read_num_entry("Screen", "Width", 1920), m_wm_config->read_num_entry("Screen", "Height", 1080)); - 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", ""))); + m_arrow_cursor = get_cursor("Arrow", { 2, 2 }); + m_resize_horizontally_cursor = get_cursor("ResizeH"); + m_resize_vertically_cursor = get_cursor("ResizeV"); + m_resize_diagonally_tlbr_cursor = get_cursor("ResizeDTLBR"); + m_resize_diagonally_bltr_cursor = get_cursor("ResizeDBLTR"); + m_i_beam_cursor = get_cursor("IBeam"); + m_disallowed_cursor = get_cursor("Disallowed"); + m_move_cursor = get_cursor("Move"); m_background_color = m_wm_config->read_color_entry("Colors", "Background", Color::Red); diff --git a/Servers/WindowServer/WSWindowManager.h b/Servers/WindowServer/WSWindowManager.h index 328fe63dd29..9192a35860d 100644 --- a/Servers/WindowServer/WSWindowManager.h +++ b/Servers/WindowServer/WSWindowManager.h @@ -121,6 +121,9 @@ public: WSWindow* active_fullscreen_window() { return (m_active_window && m_active_window->is_fullscreen()) ? m_active_window : nullptr; } private: + Retained get_cursor(const String& name); + Retained get_cursor(const String& name, const Point& hotspot); + void process_mouse_event(WSMouseEvent&, WSWindow*& hovered_window); void process_event_for_doubleclick(WSWindow& window, WSMouseEvent& event); void deliver_mouse_event(WSWindow& window, WSMouseEvent& event); diff --git a/SharedGraphics/Painter.cpp b/SharedGraphics/Painter.cpp index dee577138ee..d2f5121ca4a 100644 --- a/SharedGraphics/Painter.cpp +++ b/SharedGraphics/Painter.cpp @@ -273,6 +273,32 @@ void Painter::blit_dimmed(const Point& position, const GraphicsBitmap& source, c } } +void Painter::blit_tiled(const Point& position, const GraphicsBitmap& source, const Rect& src_rect) +{ + auto dst_rect = Rect(position, src_rect.size()).translated(translation()); + auto clipped_rect = dst_rect.intersected(clip_rect()); + if (clipped_rect.is_empty()) + return; + const int first_row = clipped_rect.top() - dst_rect.top(); + const int last_row = clipped_rect.bottom() - dst_rect.top(); + const int first_column = clipped_rect.left() - dst_rect.left(); + const int last_column = clipped_rect.right() - dst_rect.left(); + RGBA32* dst = m_target->scanline(clipped_rect.y()) + clipped_rect.x(); + const RGBA32* isrc = source.scanline(0) + src_rect.left() + first_column; + const RGBA32* src = source.scanline(src_rect.top() + first_row) + src_rect.left() + first_column; + const size_t dst_skip = m_target->pitch() / sizeof(RGBA32); + const size_t src_skip = source.pitch() / sizeof(RGBA32); + + for (int row = first_row; row <= last_row; ++row) { + int y = (src - isrc) / src_skip % source.size().height(); + src = y * src_skip + isrc; + for (int x = 0; x <= (last_column - first_column); ++x) { + dst[x] = src[x % source.size().width()]; + } + dst += dst_skip; + src += src_skip; + } +} void Painter::blit_with_alpha(const Point& position, const GraphicsBitmap& source, const Rect& src_rect) { diff --git a/SharedGraphics/Painter.h b/SharedGraphics/Painter.h index f9ff6847bcd..be19ae3201e 100644 --- a/SharedGraphics/Painter.h +++ b/SharedGraphics/Painter.h @@ -27,7 +27,7 @@ public: void draw_scaled_bitmap(const Rect& dst_rect, const GraphicsBitmap&, const Rect& src_rect); void blit(const Point&, const GraphicsBitmap&, const Rect& src_rect, float opacity = 1.0f); void blit_dimmed(const Point&, const GraphicsBitmap&, const Rect& src_rect); - + void blit_tiled(const Point&, const GraphicsBitmap&, const Rect& src_rect); void draw_text(const Rect&, const char* text, int length, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None); void draw_text(const Rect&, const char* text, int length, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None); void draw_text(const Rect&, const String&, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);