diff --git a/Clock/.gitignore b/Clock/.gitignore new file mode 100644 index 0000000000..6710497633 --- /dev/null +++ b/Clock/.gitignore @@ -0,0 +1,3 @@ +*.o +*.d +Clock diff --git a/Clock/ClockWidget.cpp b/Clock/ClockWidget.cpp new file mode 100644 index 0000000000..94cf55cb35 --- /dev/null +++ b/Clock/ClockWidget.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include "ClockWidget.h" + +ClockWidget::ClockWidget(GWidget* parent) + : GWidget(parent) +{ + set_relative_rect({ 0, 0, 100, 40 }); + start_timer(300); +} + +ClockWidget::~ClockWidget() +{ +} + +void ClockWidget::paint_event(GPaintEvent&) +{ + auto now = time(nullptr); + auto& tm = *localtime(&now); + + char timeBuf[128]; + sprintf(timeBuf, "%02u:%02u:%02u", tm.tm_hour, tm.tm_min, tm.tm_sec); + + Painter painter(*this); + painter.fill_rect(rect(), Color::LightGray); + painter.draw_text(rect(), timeBuf, Painter::TextAlignment::Center, Color::Black); +} + +void ClockWidget::timer_event(GTimerEvent&) +{ + auto now = time(nullptr); + if (now == m_last_time) + return; + m_last_time = now; + update(); +} diff --git a/Clock/ClockWidget.h b/Clock/ClockWidget.h new file mode 100644 index 0000000000..d9702a575f --- /dev/null +++ b/Clock/ClockWidget.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +class ClockWidget final : public GWidget { +public: + explicit ClockWidget(GWidget* parent = nullptr); + virtual ~ClockWidget() override; + +private: + virtual void paint_event(GPaintEvent&) override; + virtual void timer_event(GTimerEvent&) override; + + time_t m_last_time { 0 }; +}; + diff --git a/Clock/Makefile b/Clock/Makefile new file mode 100644 index 0000000000..50865fd3a7 --- /dev/null +++ b/Clock/Makefile @@ -0,0 +1,35 @@ +OBJS = \ + ClockWidget.o \ + main.o + +APP = Clock + +ARCH_FLAGS = +STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc +USERLAND_FLAGS = -ffreestanding -fno-stack-protector -fno-ident +WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings +FLAVOR_FLAGS = -march=i386 -mregparm=3 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic +OPTIMIZATION_FLAGS = -Oz -fno-asynchronous-unwind-tables +INCLUDE_FLAGS = -I.. -I. -I../LibC + +DEFINES = -DSERENITY -DSANITIZE_PTRS -DUSERLAND + +CXXFLAGS = -MMD -MP $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(USERLAND_FLAGS) $(FLAVOR_FLAGS) $(ARCH_FLAGS) $(STANDARD_FLAGS) $(INCLUDE_FLAGS) $(DEFINES) +CXX = clang +LD = ld +AR = ar +LDFLAGS = -static --strip-debug -melf_i386 --build-id=none -z norelro -z now -e _start --gc-sections + +all: $(APP) + +$(APP): $(OBJS) + $(LD) -o $(APP) $(LDFLAGS) $(OBJS) ../LibGUI/LibGUI.a ../LibC/LibC.a + +.cpp.o: + @echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $< + +-include $(OBJS:%.o=%.d) + +clean: + @echo "CLEAN"; rm -f $(APPS) $(OBJS) *.d + diff --git a/Clock/main.cpp b/Clock/main.cpp new file mode 100644 index 0000000000..483d5cc88f --- /dev/null +++ b/Clock/main.cpp @@ -0,0 +1,21 @@ +#include +#include +#include "ClockWidget.h" + +int main(int, char**) +{ + GEventLoop loop; + + auto* window = new GWindow; + window->set_title("Clock"); + window->set_rect({ 100, 100, 100, 40 }); + + auto* clock_widget = new ClockWidget; + clock_widget->set_relative_rect({ 0, 0, 100, 40 }); + window->set_main_widget(clock_widget); + + window->show(); + return loop.exec(); +} + + diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 81fd6ebaa1..3fe0cfb9b1 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -26,7 +26,8 @@ //#define SPAWN_GUITEST #define SPAWN_GUITEST2 -#define SPAWN_FONTEDITOR +#define SPAWN_CLOCK +//#define SPAWN_FONTEDITOR //#define SPAWN_MULTIPLE_SHELLS //#define STRESS_TEST_SPAWNING @@ -111,6 +112,9 @@ static void init_stage2() #ifdef SPAWN_GUITEST2 Process::create_user_process("/bin/guitest2", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, move(environment), tty0); #endif +#ifdef SPAWN_CLOCK + Process::create_user_process("/bin/Clock", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, move(environment), tty0); +#endif #ifdef SPAWN_FONTEDITOR Process::create_user_process("/bin/FontEditor", (uid_t)100, (gid_t)100, (pid_t)0, error, { }, move(environment), tty0); #endif diff --git a/Kernel/makeall.sh b/Kernel/makeall.sh index 576030aea7..8c41d8f381 100755 --- a/Kernel/makeall.sh +++ b/Kernel/makeall.sh @@ -12,6 +12,8 @@ make -C ../Terminal clean && \ make -C ../Terminal && \ make -C ../FontEditor clean && \ make -C ../FontEditor && \ +make -C ../Clock clean && \ +make -C ../Clock && \ make clean &&\ make && \ sudo ./sync.sh diff --git a/Kernel/makeuserland.sh b/Kernel/makeuserland.sh index e9f43c15a1..cedeb0e99c 100755 --- a/Kernel/makeuserland.sh +++ b/Kernel/makeuserland.sh @@ -8,6 +8,8 @@ make -C ../LibGUI clean && \ make -C ../LibGUI && \ make -C ../Terminal clean && \ make -C ../Terminal && \ +make -C ../Clock clean && \ +make -C ../Clock && \ make -C ../Userland clean && \ make -C ../Userland && \ sudo ./sync.sh diff --git a/Kernel/sync.sh b/Kernel/sync.sh index c71ea67092..9c93e0ffaf 100755 --- a/Kernel/sync.sh +++ b/Kernel/sync.sh @@ -47,7 +47,9 @@ cp -v ../Userland/guitest2 mnt/bin/guitest2 cp -v ../Userland/sysctl mnt/bin/sysctl cp -v ../Terminal/Terminal mnt/bin/Terminal cp -v ../FontEditor/FontEditor mnt/bin/FontEditor +cp -v ../Clock/Clock mnt/bin/Clock ln -s FontEditor mnt/bin/ff +ln -s Clock mnt/bin/cl cp -v ../Userland/dmesg mnt/bin/dmesg cp -v ../Userland/chmod mnt/bin/chmod cp -v ../Userland/top mnt/bin/top diff --git a/Userland/guitest2.cpp b/Userland/guitest2.cpp index 04fe429a37..92b254563b 100644 --- a/Userland/guitest2.cpp +++ b/Userland/guitest2.cpp @@ -18,56 +18,8 @@ #include #include -class ClockWidget final : public GWidget { -public: - explicit ClockWidget(GWidget* parent = nullptr); - virtual ~ClockWidget() override { } - -private: - virtual void paint_event(GPaintEvent&) override; - virtual void timer_event(GTimerEvent&) override; - virtual void mousedown_event(GMouseEvent&) override; - - dword m_last_time { 0 }; -}; - -ClockWidget::ClockWidget(GWidget* parent) - : GWidget(parent) -{ - set_relative_rect({ 0, 0, 100, 40 }); - start_timer(250); -} - -void ClockWidget::paint_event(GPaintEvent&) -{ - auto now = time(nullptr); - auto& tm = *localtime(&now); - - char timeBuf[128]; - sprintf(timeBuf, "%02u:%02u:%02u", tm.tm_hour, tm.tm_min, tm.tm_sec); - - Painter painter(*this); - painter.fill_rect(rect(), Color::LightGray); - painter.draw_text(rect(), timeBuf, Painter::TextAlignment::Center, Color::Black); -} - -void ClockWidget::timer_event(GTimerEvent&) -{ - auto now = time(nullptr); - if (now == m_last_time) - return; - m_last_time = now; - update(); -} - -void ClockWidget::mousedown_event(GMouseEvent&) -{ - update(); -} - static GWindow* make_font_test_window(); static GWindow* make_launcher_window(); -static GWindow* make_clock_window(); void handle_sigchld(int) { @@ -90,9 +42,6 @@ int main(int argc, char** argv) auto* launcher_window = make_launcher_window(); launcher_window->show(); - auto* clock_window = make_clock_window(); - clock_window->show(); - return loop.exec(); } @@ -199,16 +148,3 @@ GWindow* make_launcher_window() return window; } - -GWindow* make_clock_window() -{ - auto* window = new GWindow; - window->set_title("Clock"); - window->set_rect({ 900, 700, 100, 40 }); - - auto* clock_widget = new ClockWidget; - clock_widget->set_relative_rect({ 0, 0, 100, 40 }); - window->set_main_widget(clock_widget); - - return window; -}