TaskbarWindow.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "TaskbarWindow.h"
  2. #include "TaskbarWidget.h"
  3. #include <LibGUI/GWindow.h>
  4. #include <LibGUI/GDesktop.h>
  5. #include <LibGUI/GEventLoop.h>
  6. #include <LibGUI/GButton.h>
  7. #include <WindowServer/WSAPITypes.h>
  8. #include <stdio.h>
  9. TaskbarWindow::TaskbarWindow()
  10. {
  11. set_window_type(GWindowType::Taskbar);
  12. set_title("Taskbar");
  13. set_should_exit_event_loop_on_close(true);
  14. on_screen_rect_change(GDesktop::the().rect());
  15. GDesktop::the().on_rect_change = [this] (const Rect& rect) { on_screen_rect_change(rect); };
  16. auto* widget = new TaskbarWidget(m_window_list);
  17. set_main_widget(widget);
  18. m_window_list.aid_create_button = [this] {
  19. return create_button();
  20. };
  21. }
  22. TaskbarWindow::~TaskbarWindow()
  23. {
  24. }
  25. void TaskbarWindow::on_screen_rect_change(const Rect& rect)
  26. {
  27. Rect new_rect { rect.x(), rect.bottom() - taskbar_height() + 1, rect.width(), taskbar_height() };
  28. set_rect(new_rect);
  29. }
  30. GButton* TaskbarWindow::create_button()
  31. {
  32. auto* button = new GButton(main_widget());
  33. button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
  34. button->set_preferred_size({ 100, 22 });
  35. button->set_checkable(true);
  36. return button;
  37. }
  38. void TaskbarWindow::wm_event(GWMEvent& event)
  39. {
  40. WindowIdentifier identifier { event.client_id(), event.window_id() };
  41. switch (event.type()) {
  42. case GEvent::WM_WindowAdded: {
  43. auto& added_event = static_cast<GWMWindowAddedEvent&>(event);
  44. printf("WM_WindowAdded: client_id=%d, window_id=%d, title=%s, rect=%s, is_active=%u\n",
  45. added_event.client_id(),
  46. added_event.window_id(),
  47. added_event.title().characters(),
  48. added_event.rect().to_string().characters(),
  49. added_event.is_active()
  50. );
  51. auto& window = m_window_list.ensure_window(identifier);
  52. window.set_title(added_event.title());
  53. window.set_rect(added_event.rect());
  54. window.set_active(added_event.is_active());
  55. window.button()->set_caption(window.title());
  56. window.button()->set_checked(window.is_active());
  57. update();
  58. break;
  59. }
  60. case GEvent::WM_WindowRemoved: {
  61. auto& removed_event = static_cast<GWMWindowRemovedEvent&>(event);
  62. printf("WM_WindowRemoved: client_id=%d, window_id=%d\n",
  63. removed_event.client_id(),
  64. removed_event.window_id()
  65. );
  66. m_window_list.remove_window(identifier);
  67. update();
  68. break;
  69. }
  70. case GEvent::WM_WindowStateChanged: {
  71. auto& changed_event = static_cast<GWMWindowStateChangedEvent&>(event);
  72. printf("WM_WindowStateChanged: client_id=%d, window_id=%d, title=%s, rect=%s, is_active=%u\n",
  73. changed_event.client_id(),
  74. changed_event.window_id(),
  75. changed_event.title().characters(),
  76. changed_event.rect().to_string().characters(),
  77. changed_event.is_active()
  78. );
  79. auto& window = m_window_list.ensure_window(identifier);
  80. window.set_title(changed_event.title());
  81. window.set_rect(changed_event.rect());
  82. window.set_active(changed_event.is_active());
  83. window.button()->set_caption(changed_event.title());
  84. window.button()->set_checked(changed_event.is_active());
  85. break;
  86. }
  87. default:
  88. break;
  89. }
  90. }