mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
can now tile background and made sure the IRC choose server popup still works
This commit is contained in:
parent
50154a23cb
commit
c23882dde1
Notes:
sideshowbarker
2024-07-19 13:53:58 +09:00
Author: https://github.com/alexispurslane Commit: https://github.com/SerenityOS/serenity/commit/c23882dde1f Pull-request: https://github.com/SerenityOS/serenity/pull/118 Reviewed-by: https://github.com/awesomekling
15 changed files with 127 additions and 44 deletions
|
@ -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)
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ private:
|
|||
|
||||
void on_socket_connected();
|
||||
|
||||
String m_hostname { "none" };
|
||||
String m_hostname;
|
||||
int m_port { 6667 };
|
||||
|
||||
CTCPSocket* m_socket { nullptr };
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
[Window]
|
||||
Opacity=150
|
||||
Opacity=255
|
||||
|
|
|
@ -34,3 +34,6 @@ MenuSelectionColor=132,53,26
|
|||
|
||||
[Input]
|
||||
DoubleClickSpeed=250
|
||||
|
||||
[Background]
|
||||
Mode=tile
|
||||
|
|
|
@ -112,19 +112,25 @@ Color CConfigFile::read_color_entry(const String& group, const String &key, Colo
|
|||
return default_value;
|
||||
}
|
||||
|
||||
Vector<String> 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;
|
||||
}
|
||||
|
|
|
@ -3,15 +3,15 @@
|
|||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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 $<
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <AK/BufferStream.h>
|
||||
#include "DNSPacket.h"
|
||||
#include "DNSRecord.h"
|
||||
#include <LibCore/CConfigFile.h>
|
||||
|
||||
#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<String, IPv4Address> dns_cache;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<GraphicsBitmap> m_wallpaper;
|
||||
};
|
||||
|
|
|
@ -112,6 +112,25 @@ WSWindowManager::~WSWindowManager()
|
|||
{
|
||||
}
|
||||
|
||||
Retained<WSCursor> 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<WSCursor> 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);
|
||||
|
||||
|
|
|
@ -121,6 +121,9 @@ public:
|
|||
WSWindow* active_fullscreen_window() { return (m_active_window && m_active_window->is_fullscreen()) ? m_active_window : nullptr; }
|
||||
|
||||
private:
|
||||
Retained<WSCursor> get_cursor(const String& name);
|
||||
Retained<WSCursor> 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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue