Skip to content

Commit

Permalink
IRC client setttings, Terminal settings, more WM settings
Browse files Browse the repository at this point in the history
  • Loading branch information
alexispurslane authored and awesomekling committed May 27, 2019
1 parent 63486b8 commit e3f81bc
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 54 deletions.
14 changes: 8 additions & 6 deletions Applications/IRCClient/IRCAppWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ void IRCAppWindow::setup_client()
m_client.join_channel("#test");
};

GInputBox input_box("Enter server:", "Connect to server", this);
auto result = input_box.exec();
if (result == GInputBox::ExecCancel)
::exit(0);

m_client.set_server(input_box.text_value(), 6667);
if (m_client.hostname() == "none") {
GInputBox input_box("Enter server:", "Connect to server", this);
auto result = input_box.exec();
if (result == GInputBox::ExecCancel)
::exit(0);

m_client.set_server(input_box.text_value(), 6667);
}
update_title();
bool success = m_client.connect();
ASSERT(success);
Expand Down
14 changes: 13 additions & 1 deletion Applications/IRCClient/IRCClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ IRCClient::IRCClient()
: m_nickname("seren1ty")
, m_client_window_list_model(IRCWindowListModel::create(*this))
, m_log(IRCLogBuffer::create())
, m_config(CConfigFile::get_for_app("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_port = m_config->read_num_entry("Connection", "Port", 6667);
}

IRCClient::~IRCClient()
Expand All @@ -53,8 +57,16 @@ void IRCClient::on_socket_connected()
send_user();
send_nick();

if (on_connect)
if (on_connect) {
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) {
join_channel(channel);
dbgprintf("IRCClient: Auto joining channel: %s\n", channel.characters());
}
on_connect();
}
}

bool IRCClient::connect()
Expand Down
4 changes: 3 additions & 1 deletion Applications/IRCClient/IRCClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <AK/CircularQueue.h>
#include <AK/Function.h>
#include <LibCore/CTCPSocket.h>
#include <LibCore/CConfigFile.h>
#include "IRCLogBuffer.h"
#include "IRCWindow.h"

Expand Down Expand Up @@ -111,7 +112,7 @@ class IRCClient final : public CObject {

void on_socket_connected();

String m_hostname;
String m_hostname { "none" };
int m_port { 6667 };

CTCPSocket* m_socket { nullptr };
Expand All @@ -127,4 +128,5 @@ class IRCClient final : public CObject {

Retained<IRCWindowListModel> m_client_window_list_model;
Retained<IRCLogBuffer> m_log;
Retained<CConfigFile> m_config;
};
18 changes: 14 additions & 4 deletions Applications/Terminal/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,30 @@

//#define TERMINAL_DEBUG

Terminal::Terminal(int ptm_fd)
Terminal::Terminal(int ptm_fd, RetainPtr<CConfigFile> config)
: m_ptm_fd(ptm_fd)
, m_notifier(ptm_fd, CNotifier::Read)
, m_config(config)
{
set_frame_shape(FrameShape::Container);
set_frame_shadow(FrameShadow::Sunken);
set_frame_thickness(2);

m_cursor_blink_timer.set_interval(500);
dbgprintf("Terminal: Load config file from %s\n", m_config->file_name().characters());
m_cursor_blink_timer.set_interval(m_config->read_num_entry("Text",
"CursorBlinkInterval",
500));
m_cursor_blink_timer.on_timeout = [this] {
m_cursor_blink_state = !m_cursor_blink_state;
update_cursor();
};

set_font(Font::default_fixed_width_font());
auto font_entry = m_config->read_entry("Text", "Font", "default");
if (font_entry == "default")
set_font(Font::default_fixed_width_font());
else
set_font(Font::load_from_file(font_entry));

m_notifier.on_ready_to_read = [this]{
byte buffer[BUFSIZ];
ssize_t nread = read(m_ptm_fd, buffer, sizeof(buffer));
Expand All @@ -53,7 +62,8 @@ Terminal::Terminal(int ptm_fd)

m_line_height = font().glyph_height() + m_line_spacing;

set_size(80, 25);
set_size(m_config->read_num_entry("Window", "Width", 80),
m_config->read_num_entry("Window", "Height", 25));
}

Terminal::Line::Line(word columns)
Expand Down
7 changes: 6 additions & 1 deletion Applications/Terminal/Terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
#include <LibGUI/GFrame.h>
#include <LibCore/CNotifier.h>
#include <LibCore/CTimer.h>
#include <LibCore/CConfigFile.h>

class Font;

class Terminal final : public GFrame {
public:
explicit Terminal(int ptm_fd);
explicit Terminal(int ptm_fd, RetainPtr<CConfigFile> config);
virtual ~Terminal() override;

void create_window();
Expand All @@ -26,6 +27,8 @@ class Terminal final : public GFrame {

void set_opacity(float);

RetainPtr<CConfigFile> config() const { return m_config; }

private:
typedef Vector<unsigned, 4> ParamVector;

Expand All @@ -42,6 +45,7 @@ class Terminal final : public GFrame {
void invalidate_cursor();
void set_window_title(const String&);


void inject_string(const String&);
void unimplemented_escape();
void unimplemented_xterm_escape();
Expand Down Expand Up @@ -165,4 +169,5 @@ class Terminal final : public GFrame {
int m_glyph_width { 0 };

CTimer m_cursor_blink_timer;
RetainPtr<CConfigFile> m_config;
};
10 changes: 9 additions & 1 deletion Applications/Terminal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ int main(int argc, char** argv)
window->set_double_buffering_enabled(false);
window->set_should_exit_event_loop_on_close(true);

Terminal terminal(ptm_fd);
RetainPtr<CConfigFile> config = CConfigFile::get_for_app("Terminal");
Terminal terminal(ptm_fd, config);
window->set_has_alpha_channel(true);
window->set_main_widget(&terminal);
window->move_to(300, 300);
Expand All @@ -119,6 +120,9 @@ int main(int argc, char** argv)
slider->set_range(0, 100);
slider->set_value(100);

auto new_opacity = config->read_num_entry("Window", "Opacity", 255);
terminal.set_opacity((float)new_opacity / 255.0);

auto menubar = make<GMenuBar>();

auto app_menu = make<GMenu>("Terminal");
Expand All @@ -136,6 +140,9 @@ int main(int argc, char** argv)
GFontDatabase::the().for_each_fixed_width_font([&] (const String& font_name) {
font_menu->add_action(GAction::create(font_name, [&terminal] (const GAction& action) {
terminal.set_font(GFontDatabase::the().get_by_name(action.text()));
auto metadata = GFontDatabase::the().get_metadata_by_name(action.text());
terminal.config()->write_entry("Text", "Font", metadata.path);
terminal.config()->sync();
terminal.force_repaint();
}));
});
Expand All @@ -149,5 +156,6 @@ int main(int argc, char** argv)

app.set_menubar(move(menubar));

config->sync();
return app.exec();
}
7 changes: 7 additions & 0 deletions Base/home/anon/IRCClient.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[User]
Nickname=anon_seren1ty

[Connection]
Server=chat.freenode.net
Port=6667
AutoJoinChannels=#serenityos
2 changes: 2 additions & 0 deletions Base/home/anon/Terminal.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Window]
Opacity=150
3 changes: 3 additions & 0 deletions Base/home/anon/WindowManager.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ HighlightWindowBorder2=250,187,187
HighlightWindowTitle=255,255,255

MenuSelectionColor=132,53,26

[Input]
DoubleClickSpeed=250
16 changes: 10 additions & 6 deletions LibGUI/GFontDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

class Font;

struct Metadata {
String path;
bool is_fixed_width;
int glyph_height;
};

class GFontDatabase {
public:
static GFontDatabase& the();
Expand All @@ -14,15 +20,13 @@ class GFontDatabase {
void for_each_font(Function<void(const String&)>);
void for_each_fixed_width_font(Function<void(const String&)>);

Metadata get_metadata_by_name(const String& name) const {
return m_name_to_metadata.get(name);
};

private:
GFontDatabase();
~GFontDatabase();

struct Metadata {
String path;
bool is_fixed_width;
int glyph_height;
};

HashMap<String, Metadata> m_name_to_metadata;
};
3 changes: 2 additions & 1 deletion Servers/WindowServer/WSCompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ void WSCompositor::compose()
if (wm.any_opaque_window_contains_rect(dirty_rect))
continue;
m_back_painter->fill_rect(dirty_rect, wm.m_background_color);
m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect);
if (m_wallpaper)
m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect);
}

auto compose_window = [&] (WSWindow& window) -> IterationDecision {
Expand Down
41 changes: 11 additions & 30 deletions Servers/WindowServer/WSWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ WSWindowManager::WSWindowManager()
{
s_the = this;


m_username = getlogin();

reload_config();
reload_config(false);

struct AppMenuItem {
const char *binary_name;
Expand All @@ -63,13 +62,7 @@ WSWindowManager::WSWindowManager()
}

m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, WSMenuItem::Separator));
m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 100, "640x480"));
m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 101, "800x600"));
m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 102, "1024x768"));
m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 103, "1280x720"));
m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 104, "1440x900"));
m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 105, "1920x1080"));
m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 106, "2560x1440"));
m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 100, "Reload WM Config File"));
m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, WSMenuItem::Separator));
m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 200, "About..."));
m_system_menu->on_item_activation = [this, apps] (WSMenuItem& item) {
Expand All @@ -82,25 +75,7 @@ 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);
reload_config(true);
break;
}
if (item.identifier() == 200) {
Expand Down Expand Up @@ -137,10 +112,16 @@ WSWindowManager::~WSWindowManager()
{
}

void WSWindowManager::reload_config()
void WSWindowManager::reload_config(bool set_screen)
{
m_wm_config = CConfigFile::get_for_app("WindowManager");

m_double_click_speed = m_wm_config->read_num_entry("Input", "DoubleClickSpeed", 250);

if (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", "")));
Expand Down Expand Up @@ -669,7 +650,7 @@ void WSWindowManager::process_event_for_doubleclick(WSWindow& window, WSMouseEve

// FIXME: It might be a sensible idea to also add a distance travel check.
// If the pointer moves too far, it's not a double click.
if (elapsed_since_last_click < 250) {
if (elapsed_since_last_click < m_double_click_speed) {
#if defined(DOUBLECLICK_DEBUG)
dbgprintf("Transforming MouseUp to MouseDoubleClick!\n");
#endif
Expand Down
5 changes: 2 additions & 3 deletions Servers/WindowServer/WSWindowManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class WSWindowManager : public CObject {
virtual ~WSWindowManager() override;

RetainPtr<CConfigFile> wm_config() const { return m_wm_config; }
void set_wm_config(Retained<CConfigFile> conf) { m_wm_config = conf; }
void reload_config(bool);

void add_window(WSWindow&);
void remove_window(WSWindow&);
Expand Down Expand Up @@ -156,8 +156,6 @@ class WSWindowManager : public CObject {
void tell_wm_listener_about_window_rect(WSWindow& listener, WSWindow&);
void pick_new_active_window();

void reload_config();

RetainPtr<WSCursor> m_arrow_cursor;
RetainPtr<WSCursor> m_resize_horizontally_cursor;
RetainPtr<WSCursor> m_resize_vertically_cursor;
Expand Down Expand Up @@ -199,6 +197,7 @@ class WSWindowManager : public CObject {
CElapsedTimer m_middle_click_clock;
};
DoubleClickInfo m_double_click_info;
unsigned int m_double_click_speed;

WeakPtr<WSWindow> m_active_window;
WeakPtr<WSWindow> m_hovered_window;
Expand Down

0 comments on commit e3f81bc

Please sign in to comment.