guitest2.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <errno.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <fcntl.h>
  7. #include <assert.h>
  8. #include <time.h>
  9. #include <Kernel/Syscall.h>
  10. #include <SharedGraphics/GraphicsBitmap.h>
  11. #include <SharedGraphics/Painter.h>
  12. #include <LibGUI/GWindow.h>
  13. #include <LibGUI/GWidget.h>
  14. #include <LibGUI/GLabel.h>
  15. #include <LibGUI/GButton.h>
  16. #include <LibGUI/GTextBox.h>
  17. #include <LibGUI/GCheckBox.h>
  18. #include <LibGUI/GApplication.h>
  19. #include <signal.h>
  20. static GWindow* make_launcher_window();
  21. void handle_sigchld(int)
  22. {
  23. dbgprintf("Got SIGCHLD\n");
  24. int pid = waitpid(-1, nullptr, 0);
  25. dbgprintf("waitpid() returned %d\n", pid);
  26. ASSERT(pid > 0);
  27. }
  28. int main(int argc, char** argv)
  29. {
  30. GApplication app(argc, argv);
  31. signal(SIGCHLD, handle_sigchld);
  32. auto* launcher_window = make_launcher_window();
  33. launcher_window->set_should_exit_app_on_close(true);
  34. launcher_window->show();
  35. return app.exec();
  36. }
  37. GWindow* make_launcher_window()
  38. {
  39. auto* window = new GWindow;
  40. window->set_title("guitest2");
  41. window->set_rect({ 100, 400, 100, 230 });
  42. auto* widget = new GWidget;
  43. window->set_main_widget(widget);
  44. widget->set_relative_rect({ 0, 0, 100, 230 });
  45. auto* label = new GLabel(widget);
  46. label->set_relative_rect({ 0, 0, 100, 20 });
  47. label->set_text("Apps");
  48. auto* terminal_button = new GButton(widget);
  49. terminal_button->set_relative_rect({ 5, 20, 90, 20 });
  50. terminal_button->set_caption("Terminal");
  51. terminal_button->on_click = [label] (GButton&) {
  52. pid_t child_pid = fork();
  53. if (!child_pid) {
  54. execve("/bin/Terminal", nullptr, nullptr);
  55. ASSERT_NOT_REACHED();
  56. } else {
  57. char buffer[32];
  58. sprintf(buffer, "PID: %d", child_pid);
  59. label->set_text(buffer);
  60. }
  61. };
  62. auto* guitest_button = new GButton(widget);
  63. guitest_button->set_relative_rect({ 5, 50, 90, 20 });
  64. guitest_button->set_caption("guitest");
  65. guitest_button->on_click = [label] (GButton&) {
  66. pid_t child_pid = fork();
  67. if (!child_pid) {
  68. execve("/bin/guitest", nullptr, nullptr);
  69. ASSERT_NOT_REACHED();
  70. } else {
  71. char buffer[32];
  72. sprintf(buffer, "PID: %d", child_pid);
  73. label->set_text(buffer);
  74. }
  75. };
  76. auto* dummy_button = new GButton(widget);
  77. dummy_button->set_relative_rect({ 5, 80, 90, 20 });
  78. dummy_button->set_caption("Dummy");
  79. auto* textbox = new GTextBox(widget);
  80. textbox->set_relative_rect({ 5, 110, 90, 20 });
  81. textbox->on_return_pressed = [window] (GTextBox& textbox) {
  82. window->set_title(textbox.text());
  83. };
  84. auto* other_textbox = new GTextBox(widget);
  85. other_textbox->set_relative_rect({ 5, 140, 90, 20 });
  86. auto* checkbox = new GCheckBox(widget);
  87. checkbox->set_relative_rect({ 5, 170, 90, 20 });
  88. checkbox->set_caption("CheckBox");
  89. window->set_focused_widget(textbox);
  90. auto* close_button = new GButton(widget);
  91. close_button->set_relative_rect({ 5, 200, 90, 20 });
  92. close_button->set_caption("Close");
  93. close_button->on_click = [window] (GButton&) {
  94. window->close();
  95. };
  96. return window;
  97. }