WSWindowManager.cpp 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  1. #include "WSWindowManager.h"
  2. #include "WSWindow.h"
  3. #include "WSScreen.h"
  4. #include "WSEventLoop.h"
  5. #include <SharedGraphics/Font.h>
  6. #include <SharedGraphics/Painter.h>
  7. #include <SharedGraphics/CharacterBitmap.h>
  8. #include <AK/StdLibExtras.h>
  9. #include <errno.h>
  10. #include "WSMenu.h"
  11. #include "WSMenuBar.h"
  12. #include "WSMenuItem.h"
  13. #include <WindowServer/WSClientConnection.h>
  14. #include <unistd.h>
  15. #include <stdio.h>
  16. #include <time.h>
  17. #include <SharedGraphics/StylePainter.h>
  18. #include <SharedGraphics/PNGLoader.h>
  19. #include <WindowServer/WSCursor.h>
  20. #include <WindowServer/WSButton.h>
  21. #include <LibCore/CTimer.h>
  22. //#define DEBUG_COUNTERS
  23. //#define RESIZE_DEBUG
  24. static WSWindowManager* s_the;
  25. WSWindowManager& WSWindowManager::the()
  26. {
  27. ASSERT(s_the);
  28. return *s_the;
  29. }
  30. void WSWindowManager::flip_buffers()
  31. {
  32. swap(m_front_bitmap, m_back_bitmap);
  33. swap(m_front_painter, m_back_painter);
  34. int new_y_offset = m_buffers_are_flipped ? 0 : m_screen_rect.height();
  35. WSScreen::the().set_y_offset(new_y_offset);
  36. m_buffers_are_flipped = !m_buffers_are_flipped;
  37. }
  38. WSWindowManager::WSWindowManager()
  39. : m_screen(WSScreen::the())
  40. , m_screen_rect(m_screen.rect())
  41. , m_flash_flush(false)
  42. {
  43. s_the = this;
  44. #ifndef DEBUG_COUNTERS
  45. (void)m_compose_count;
  46. (void)m_flush_count;
  47. #endif
  48. auto size = m_screen_rect.size();
  49. m_front_bitmap = GraphicsBitmap::create_wrapper(GraphicsBitmap::Format::RGB32, size, m_screen.scanline(0));
  50. m_back_bitmap = GraphicsBitmap::create_wrapper(GraphicsBitmap::Format::RGB32, size, m_screen.scanline(size.height()));
  51. m_front_painter = make<Painter>(*m_front_bitmap);
  52. m_back_painter = make<Painter>(*m_back_bitmap);
  53. m_front_painter->set_font(font());
  54. m_back_painter->set_font(font());
  55. m_background_color = Color(50, 50, 50);
  56. m_active_window_border_color = Color(110, 34, 9);
  57. m_active_window_border_color2 = Color(244, 202, 158);
  58. m_active_window_title_color = Color::White;
  59. m_inactive_window_border_color = Color(128, 128, 128);
  60. m_inactive_window_border_color2 = Color(192, 192, 192);
  61. m_inactive_window_title_color = Color(213, 208, 199);
  62. m_dragging_window_border_color = Color(161, 50, 13);
  63. m_dragging_window_border_color2 = Color(250, 220, 187);
  64. m_dragging_window_title_color = Color::White;
  65. m_highlight_window_border_color = Color::from_rgb(0xa10d0d);
  66. m_highlight_window_border_color2 = Color::from_rgb(0xfabbbb);
  67. m_highlight_window_title_color = Color::White;
  68. m_arrow_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/arrow.png"), { 2, 2 });
  69. m_resize_horizontally_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/resize-horizontal.png"));
  70. m_resize_vertically_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/resize-vertical.png"));
  71. m_resize_diagonally_tlbr_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/resize-diagonal-tlbr.png"));
  72. m_resize_diagonally_bltr_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/resize-diagonal-bltr.png"));
  73. m_i_beam_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/i-beam.png"));
  74. m_disallowed_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/disallowed.png"));
  75. m_move_cursor = WSCursor::create(*GraphicsBitmap::load_from_file("/res/cursors/move.png"));
  76. m_wallpaper_path = "/res/wallpapers/retro.rgb";
  77. m_wallpaper = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, m_wallpaper_path, { 1024, 768 });
  78. m_username = getlogin();
  79. m_menu_selection_color = Color::from_rgb(0x84351a);
  80. {
  81. byte system_menu_name[] = { 0xf8, 0 };
  82. m_system_menu = make<WSMenu>(nullptr, -1, String((const char*)system_menu_name));
  83. m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 0, "Open Terminal..."));
  84. m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 1, "Open ProcessManager..."));
  85. m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, WSMenuItem::Separator));
  86. m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 100, "640x480"));
  87. m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 101, "800x600"));
  88. m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 102, "1024x768"));
  89. m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 103, "1440x900"));
  90. m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 104, "1920x1080"));
  91. m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, WSMenuItem::Separator));
  92. m_system_menu->add_item(make<WSMenuItem>(*m_system_menu, 200, "About..."));
  93. m_system_menu->on_item_activation = [this] (WSMenuItem& item) {
  94. if (item.identifier() == 0) {
  95. if (fork() == 0) {
  96. execl("/bin/Terminal", "/bin/Terminal", nullptr);
  97. ASSERT_NOT_REACHED();
  98. }
  99. return;
  100. }
  101. if (item.identifier() == 1) {
  102. if (fork() == 0) {
  103. execl("/bin/ProcessManager", "/bin/ProcessManager", nullptr);
  104. ASSERT_NOT_REACHED();
  105. }
  106. return;
  107. }
  108. switch (item.identifier()) {
  109. case 100: set_resolution(640, 480); break;
  110. case 101: set_resolution(800, 600); break;
  111. case 102: set_resolution(1024, 768); break;
  112. case 103: set_resolution(1440, 900); break;
  113. case 104: set_resolution(1920, 1080); break;
  114. }
  115. if (item.identifier() == 200) {
  116. if (fork() == 0) {
  117. execl("/bin/About", "/bin/About", nullptr);
  118. ASSERT_NOT_REACHED();
  119. }
  120. return;
  121. }
  122. #ifdef DEBUG_MENUS
  123. dbgprintf("WSMenu 1 item activated: '%s'\n", item.text().characters());
  124. #endif
  125. };
  126. }
  127. // NOTE: This ensures that the system menu has the correct dimensions.
  128. set_current_menubar(nullptr);
  129. new CTimer(300, [this] {
  130. static time_t last_update_time;
  131. time_t now = time(nullptr);
  132. if (now != last_update_time || m_cpu_monitor.is_dirty()) {
  133. tick_clock();
  134. last_update_time = now;
  135. m_cpu_monitor.set_dirty(false);
  136. }
  137. });
  138. invalidate();
  139. compose();
  140. }
  141. WSWindowManager::~WSWindowManager()
  142. {
  143. }
  144. const Font& WSWindowManager::font() const
  145. {
  146. return Font::default_font();
  147. }
  148. const Font& WSWindowManager::window_title_font() const
  149. {
  150. return Font::default_bold_font();
  151. }
  152. const Font& WSWindowManager::menu_font() const
  153. {
  154. return Font::default_font();
  155. }
  156. const Font& WSWindowManager::app_menu_font() const
  157. {
  158. return Font::default_bold_font();
  159. }
  160. void WSWindowManager::tick_clock()
  161. {
  162. invalidate(menubar_rect());
  163. }
  164. bool WSWindowManager::set_wallpaper(const String& path)
  165. {
  166. auto bitmap = load_png(path);
  167. if (!bitmap)
  168. return false;
  169. m_wallpaper_path = path;
  170. m_wallpaper = move(bitmap);
  171. invalidate();
  172. return true;
  173. }
  174. void WSWindowManager::set_resolution(int width, int height)
  175. {
  176. if (m_screen_rect.width() == width && m_screen_rect.height() == height)
  177. return;
  178. m_wallpaper_path = { };
  179. m_wallpaper = nullptr;
  180. m_screen.set_resolution(width, height);
  181. m_screen_rect = m_screen.rect();
  182. m_front_bitmap = GraphicsBitmap::create_wrapper(GraphicsBitmap::Format::RGB32, { width, height }, m_screen.scanline(0));
  183. m_back_bitmap = GraphicsBitmap::create_wrapper(GraphicsBitmap::Format::RGB32, { width, height }, m_screen.scanline(height));
  184. m_front_painter = make<Painter>(*m_front_bitmap);
  185. m_back_painter = make<Painter>(*m_back_bitmap);
  186. m_buffers_are_flipped = false;
  187. invalidate();
  188. compose();
  189. WSClientConnection::for_each_client([&] (WSClientConnection& client) {
  190. client.notify_about_new_screen_rect(m_screen_rect);
  191. });
  192. }
  193. template<typename Callback>
  194. void WSWindowManager::for_each_active_menubar_menu(Callback callback)
  195. {
  196. callback(*m_system_menu);
  197. if (m_current_menubar)
  198. m_current_menubar->for_each_menu(callback);
  199. }
  200. int WSWindowManager::menubar_menu_margin() const
  201. {
  202. return 16;
  203. }
  204. void WSWindowManager::set_current_menu(WSMenu* menu)
  205. {
  206. if (m_current_menu == menu)
  207. return;
  208. if (m_current_menu)
  209. m_current_menu->close();
  210. if (menu)
  211. m_current_menu = menu->make_weak_ptr();
  212. }
  213. void WSWindowManager::set_current_menubar(WSMenuBar* menubar)
  214. {
  215. if (menubar)
  216. m_current_menubar = menubar->make_weak_ptr();
  217. else
  218. m_current_menubar = nullptr;
  219. #ifdef DEBUG_MENUS
  220. dbgprintf("[WM] Current menubar is now %p\n", menubar);
  221. #endif
  222. Point next_menu_location { menubar_menu_margin() / 2, 0 };
  223. int index = 0;
  224. for_each_active_menubar_menu([&] (WSMenu& menu) {
  225. int text_width = index == 1 ? Font::default_bold_font().width(menu.name()) : font().width(menu.name());
  226. menu.set_rect_in_menubar({ next_menu_location.x() - menubar_menu_margin() / 2, 0, text_width + menubar_menu_margin(), menubar_rect().height() - 1 });
  227. menu.set_text_rect_in_menubar({ next_menu_location, { text_width, menubar_rect().height() } });
  228. next_menu_location.move_by(menu.rect_in_menubar().width(), 0);
  229. ++index;
  230. return true;
  231. });
  232. invalidate(menubar_rect());
  233. }
  234. void WSWindowManager::add_window(WSWindow& window)
  235. {
  236. m_windows.set(&window);
  237. m_windows_in_order.append(&window);
  238. set_active_window(&window);
  239. if (m_switcher.is_visible() && window.type() != WSWindowType::WindowSwitcher)
  240. m_switcher.refresh();
  241. if (window.listens_to_wm_events()) {
  242. for_each_window([&] (WSWindow& other_window) {
  243. if (&window != &other_window) {
  244. tell_wm_listener_about_window(window, other_window);
  245. tell_wm_listener_about_window_icon(window, other_window);
  246. }
  247. return IterationDecision::Continue;
  248. });
  249. }
  250. tell_wm_listeners_window_state_changed(window);
  251. }
  252. void WSWindowManager::move_to_front_and_make_active(WSWindow& window)
  253. {
  254. if (window.is_blocked_by_modal_window())
  255. return;
  256. if (m_windows_in_order.tail() != &window)
  257. invalidate(window);
  258. m_windows_in_order.remove(&window);
  259. m_windows_in_order.append(&window);
  260. set_active_window(&window);
  261. }
  262. void WSWindowManager::remove_window(WSWindow& window)
  263. {
  264. if (!m_windows.contains(&window))
  265. return;
  266. invalidate(window);
  267. m_windows.remove(&window);
  268. m_windows_in_order.remove(&window);
  269. if (window.is_active())
  270. pick_new_active_window();
  271. if (m_switcher.is_visible() && window.type() != WSWindowType::WindowSwitcher)
  272. m_switcher.refresh();
  273. for_each_window_listening_to_wm_events([&window] (WSWindow& listener) {
  274. if (window.client())
  275. WSEventLoop::the().post_event(listener, make<WSWMWindowRemovedEvent>(window.client()->client_id(), window.window_id()));
  276. return IterationDecision::Continue;
  277. });
  278. }
  279. void WSWindowManager::tell_wm_listener_about_window(WSWindow& listener, WSWindow& window)
  280. {
  281. if (window.client())
  282. WSEventLoop::the().post_event(listener, make<WSWMWindowStateChangedEvent>(window.client()->client_id(), window.window_id(), window.title(), window.rect(), window.is_active(), window.type(), window.is_minimized()));
  283. }
  284. void WSWindowManager::tell_wm_listener_about_window_icon(WSWindow& listener, WSWindow& window)
  285. {
  286. if (window.client())
  287. WSEventLoop::the().post_event(listener, make<WSWMWindowIconChangedEvent>(window.client()->client_id(), window.window_id(), window.icon_path()));
  288. }
  289. void WSWindowManager::tell_wm_listeners_window_state_changed(WSWindow& window)
  290. {
  291. for_each_window_listening_to_wm_events([&] (WSWindow& listener) {
  292. tell_wm_listener_about_window(listener, window);
  293. return IterationDecision::Continue;
  294. });
  295. }
  296. void WSWindowManager::tell_wm_listeners_window_icon_changed(WSWindow& window)
  297. {
  298. for_each_window_listening_to_wm_events([&] (WSWindow& listener) {
  299. tell_wm_listener_about_window_icon(listener, window);
  300. return IterationDecision::Continue;
  301. });
  302. }
  303. void WSWindowManager::notify_title_changed(WSWindow& window)
  304. {
  305. dbgprintf("[WM] WSWindow{%p} title set to '%s'\n", &window, window.title().characters());
  306. invalidate(window.frame().rect());
  307. if (m_switcher.is_visible())
  308. m_switcher.refresh();
  309. tell_wm_listeners_window_state_changed(window);
  310. }
  311. void WSWindowManager::notify_rect_changed(WSWindow& window, const Rect& old_rect, const Rect& new_rect)
  312. {
  313. UNUSED_PARAM(old_rect);
  314. UNUSED_PARAM(new_rect);
  315. #ifdef RESIZE_DEBUG
  316. dbgprintf("[WM] WSWindow %p rect changed (%d,%d %dx%d) -> (%d,%d %dx%d)\n", &window, old_rect.x(), old_rect.y(), old_rect.width(), old_rect.height(), new_rect.x(), new_rect.y(), new_rect.width(), new_rect.height());
  317. #endif
  318. if (m_switcher.is_visible() && window.type() != WSWindowType::WindowSwitcher)
  319. m_switcher.refresh();
  320. tell_wm_listeners_window_state_changed(window);
  321. }
  322. void WSWindowManager::notify_minimization_state_changed(WSWindow& window)
  323. {
  324. tell_wm_listeners_window_state_changed(window);
  325. if (window.is_active() && window.is_minimized())
  326. pick_new_active_window();
  327. }
  328. void WSWindowManager::pick_new_active_window()
  329. {
  330. for_each_visible_window_of_type_from_front_to_back(WSWindowType::Normal, [&] (WSWindow& candidate) {
  331. set_active_window(&candidate);
  332. return IterationDecision::Abort;
  333. });
  334. }
  335. void WSWindowManager::handle_menu_mouse_event(WSMenu& menu, const WSMouseEvent& event)
  336. {
  337. bool is_hover_with_any_menu_open = event.type() == WSMouseEvent::MouseMove && m_current_menu && (m_current_menu->menubar() || m_current_menu == m_system_menu);
  338. bool is_mousedown_with_left_button = event.type() == WSMouseEvent::MouseDown && event.button() == MouseButton::Left;
  339. bool should_open_menu = &menu != current_menu() && (is_hover_with_any_menu_open || is_mousedown_with_left_button);
  340. if (should_open_menu) {
  341. if (current_menu() == &menu)
  342. return;
  343. close_current_menu();
  344. if (!menu.is_empty()) {
  345. auto& menu_window = menu.ensure_menu_window();
  346. menu_window.move_to({ menu.rect_in_menubar().x(), menu.rect_in_menubar().bottom() + 2 });
  347. menu_window.set_visible(true);
  348. }
  349. m_current_menu = menu.make_weak_ptr();
  350. return;
  351. }
  352. if (event.type() == WSMouseEvent::MouseDown && event.button() == MouseButton::Left) {
  353. close_current_menu();
  354. return;
  355. }
  356. }
  357. void WSWindowManager::close_current_menu()
  358. {
  359. if (m_current_menu && m_current_menu->menu_window())
  360. m_current_menu->menu_window()->set_visible(false);
  361. m_current_menu = nullptr;
  362. }
  363. void WSWindowManager::handle_menubar_mouse_event(const WSMouseEvent& event)
  364. {
  365. for_each_active_menubar_menu([&] (WSMenu& menu) {
  366. if (menu.rect_in_menubar().contains(event.position())) {
  367. handle_menu_mouse_event(menu, event);
  368. return false;
  369. }
  370. return true;
  371. });
  372. }
  373. void WSWindowManager::start_window_drag(WSWindow& window, const WSMouseEvent& event)
  374. {
  375. #ifdef DRAG_DEBUG
  376. printf("[WM] Begin dragging WSWindow{%p}\n", &window);
  377. #endif
  378. move_to_front_and_make_active(window);
  379. m_drag_window = window.make_weak_ptr();;
  380. m_drag_origin = event.position();
  381. m_drag_window_origin = window.position();
  382. invalidate(window);
  383. }
  384. void WSWindowManager::start_window_resize(WSWindow& window, const WSMouseEvent& event)
  385. {
  386. move_to_front_and_make_active(window);
  387. constexpr ResizeDirection direction_for_hot_area[3][3] = {
  388. { ResizeDirection::UpLeft, ResizeDirection::Up, ResizeDirection::UpRight },
  389. { ResizeDirection::Left, ResizeDirection::None, ResizeDirection::Right },
  390. { ResizeDirection::DownLeft, ResizeDirection::Down, ResizeDirection::DownRight },
  391. };
  392. Rect outer_rect = window.frame().rect();
  393. ASSERT(outer_rect.contains(event.position()));
  394. int window_relative_x = event.x() - outer_rect.x();
  395. int window_relative_y = event.y() - outer_rect.y();
  396. int hot_area_row = min(2, window_relative_y / (outer_rect.height() / 3));
  397. int hot_area_column = min(2, window_relative_x / (outer_rect.width() / 3));
  398. m_resize_direction = direction_for_hot_area[hot_area_row][hot_area_column];
  399. if (m_resize_direction == ResizeDirection::None) {
  400. ASSERT(!m_resize_window);
  401. return;
  402. }
  403. #ifdef RESIZE_DEBUG
  404. printf("[WM] Begin resizing WSWindow{%p}\n", &window);
  405. #endif
  406. m_resizing_mouse_button = event.button();
  407. m_resize_window = window.make_weak_ptr();;
  408. m_resize_origin = event.position();
  409. m_resize_window_original_rect = window.rect();
  410. invalidate(window);
  411. }
  412. bool WSWindowManager::process_ongoing_window_drag(const WSMouseEvent& event, WSWindow*&)
  413. {
  414. if (!m_drag_window)
  415. return false;
  416. if (event.type() == WSEvent::MouseUp && event.button() == MouseButton::Left) {
  417. #ifdef DRAG_DEBUG
  418. printf("[WM] Finish dragging WSWindow{%p}\n", m_drag_window.ptr());
  419. #endif
  420. invalidate(*m_drag_window);
  421. m_drag_window = nullptr;
  422. return true;
  423. }
  424. if (event.type() == WSEvent::MouseMove) {
  425. #ifdef DRAG_DEBUG
  426. dbgprintf("[WM] Dragging [origin: %d,%d] now: %d,%d\n", m_drag_origin.x(), m_drag_origin.y(), event.x(), event.y());
  427. #endif
  428. Point pos = m_drag_window_origin.translated(event.position() - m_drag_origin);
  429. m_drag_window->set_position_without_repaint(pos);
  430. return true;
  431. }
  432. return false;
  433. }
  434. bool WSWindowManager::process_ongoing_window_resize(const WSMouseEvent& event, WSWindow*&)
  435. {
  436. if (!m_resize_window)
  437. return false;
  438. if (event.type() == WSEvent::MouseUp && event.button() == m_resizing_mouse_button) {
  439. #ifdef RESIZE_DEBUG
  440. printf("[WM] Finish resizing WSWindow{%p}\n", m_resize_window.ptr());
  441. #endif
  442. WSEventLoop::the().post_event(*m_resize_window, make<WSResizeEvent>(m_resize_window->rect(), m_resize_window->rect()));
  443. invalidate(*m_resize_window);
  444. m_resize_window = nullptr;
  445. m_resizing_mouse_button = MouseButton::None;
  446. return true;
  447. }
  448. if (event.type() != WSEvent::MouseMove)
  449. return false;
  450. auto old_rect = m_resize_window->rect();
  451. int diff_x = event.x() - m_resize_origin.x();
  452. int diff_y = event.y() - m_resize_origin.y();
  453. int change_x = 0;
  454. int change_y = 0;
  455. int change_w = 0;
  456. int change_h = 0;
  457. switch (m_resize_direction) {
  458. case ResizeDirection::DownRight:
  459. change_w = diff_x;
  460. change_h = diff_y;
  461. break;
  462. case ResizeDirection::Right:
  463. change_w = diff_x;
  464. break;
  465. case ResizeDirection::UpRight:
  466. change_w = diff_x;
  467. change_y = diff_y;
  468. change_h = -diff_y;
  469. break;
  470. case ResizeDirection::Up:
  471. change_y = diff_y;
  472. change_h = -diff_y;
  473. break;
  474. case ResizeDirection::UpLeft:
  475. change_x = diff_x;
  476. change_w = -diff_x;
  477. change_y = diff_y;
  478. change_h = -diff_y;
  479. break;
  480. case ResizeDirection::Left:
  481. change_x = diff_x;
  482. change_w = -diff_x;
  483. break;
  484. case ResizeDirection::DownLeft:
  485. change_x = diff_x;
  486. change_w = -diff_x;
  487. change_h = diff_y;
  488. break;
  489. case ResizeDirection::Down:
  490. change_h = diff_y;
  491. break;
  492. default:
  493. ASSERT_NOT_REACHED();
  494. }
  495. auto new_rect = m_resize_window_original_rect;
  496. Size minimum_size { 50, 50 };
  497. new_rect.set_x(new_rect.x() + change_x);
  498. new_rect.set_y(new_rect.y() + change_y);
  499. new_rect.set_width(max(minimum_size.width(), new_rect.width() + change_w));
  500. new_rect.set_height(max(minimum_size.height(), new_rect.height() + change_h));
  501. if (!m_resize_window->size_increment().is_null()) {
  502. int horizontal_incs = (new_rect.width() - m_resize_window->base_size().width()) / m_resize_window->size_increment().width();
  503. new_rect.set_width(m_resize_window->base_size().width() + horizontal_incs * m_resize_window->size_increment().width());
  504. int vertical_incs = (new_rect.height() - m_resize_window->base_size().height()) / m_resize_window->size_increment().height();
  505. new_rect.set_height(m_resize_window->base_size().height() + vertical_incs * m_resize_window->size_increment().height());
  506. }
  507. if (m_resize_window->rect() == new_rect)
  508. return true;
  509. #ifdef RESIZE_DEBUG
  510. dbgprintf("[WM] Resizing [original: %s] now: %s\n",
  511. m_resize_window_original_rect.to_string().characters(),
  512. new_rect.to_string().characters());
  513. #endif
  514. m_resize_window->set_rect(new_rect);
  515. WSEventLoop::the().post_event(*m_resize_window, make<WSResizeEvent>(old_rect, new_rect));
  516. return true;
  517. }
  518. void WSWindowManager::set_cursor_tracking_button(WSButton* button)
  519. {
  520. m_cursor_tracking_button = button ? button->make_weak_ptr() : nullptr;
  521. }
  522. void WSWindowManager::process_mouse_event(const WSMouseEvent& event, WSWindow*& event_window)
  523. {
  524. event_window = nullptr;
  525. if (process_ongoing_window_drag(event, event_window))
  526. return;
  527. if (process_ongoing_window_resize(event, event_window))
  528. return;
  529. if (m_cursor_tracking_button)
  530. return m_cursor_tracking_button->on_mouse_event(event.translated(-m_cursor_tracking_button->screen_rect().location()));
  531. // This is quite hackish, but it's how the WSButton hover effect is implemented.
  532. if (m_hovered_button && event.type() == WSEvent::MouseMove)
  533. m_hovered_button->on_mouse_event(event.translated(-m_hovered_button->screen_rect().location()));
  534. HashTable<WSWindow*> windows_who_received_mouse_event_due_to_cursor_tracking;
  535. for (auto* window = m_windows_in_order.tail(); window; window = window->prev()) {
  536. if (!window->global_cursor_tracking())
  537. continue;
  538. ASSERT(window->is_visible()); // Maybe this should be supported? Idk. Let's catch it and think about it later.
  539. ASSERT(!window->is_minimized()); // Maybe this should also be supported? Idk.
  540. windows_who_received_mouse_event_due_to_cursor_tracking.set(window);
  541. auto translated_event = event.translated(-window->position());
  542. window->event(translated_event);
  543. }
  544. if (menubar_rect().contains(event.position())) {
  545. handle_menubar_mouse_event(event);
  546. return;
  547. }
  548. if (m_current_menu && m_current_menu->menu_window()) {
  549. auto& window = *m_current_menu->menu_window();
  550. bool event_is_inside_current_menu = window.rect().contains(event.position());
  551. if (!event_is_inside_current_menu) {
  552. if (m_current_menu->hovered_item())
  553. m_current_menu->clear_hovered_item();
  554. if (event.type() == WSEvent::MouseDown || event.type() == WSEvent::MouseUp)
  555. close_current_menu();
  556. } else {
  557. event_window = &window;
  558. auto translated_event = event.translated(-window.position());
  559. window.event(translated_event);
  560. }
  561. return;
  562. }
  563. WSWindow* event_window_with_frame = nullptr;
  564. for_each_visible_window_from_front_to_back([&] (WSWindow& window) {
  565. auto window_frame_rect = window.frame().rect();
  566. if (!window_frame_rect.contains(event.position()))
  567. return IterationDecision::Continue;
  568. if (&window != m_resize_candidate.ptr())
  569. clear_resize_candidate();
  570. // First check if we should initiate a drag or resize (Logo+LMB or Logo+RMB).
  571. // In those cases, the event is swallowed by the window manager.
  572. if (window.type() == WSWindowType::Normal) {
  573. if (m_keyboard_modifiers == Mod_Logo && event.type() == WSEvent::MouseDown && event.button() == MouseButton::Left) {
  574. start_window_drag(window, event);
  575. return IterationDecision::Abort;
  576. }
  577. if (m_keyboard_modifiers == Mod_Logo && event.type() == WSEvent::MouseDown && event.button() == MouseButton::Right && !window.is_blocked_by_modal_window()) {
  578. start_window_resize(window, event);
  579. return IterationDecision::Abort;
  580. }
  581. }
  582. // Well okay, let's see if we're hitting the frame or the window inside the frame.
  583. if (window.rect().contains(event.position())) {
  584. if (window.type() == WSWindowType::Normal && event.type() == WSEvent::MouseDown)
  585. move_to_front_and_make_active(window);
  586. event_window = &window;
  587. if (!window.global_cursor_tracking() && !windows_who_received_mouse_event_due_to_cursor_tracking.contains(&window)) {
  588. auto translated_event = event.translated(-window.position());
  589. window.event(translated_event);
  590. }
  591. return IterationDecision::Abort;
  592. }
  593. // We are hitting the frame, pass the event along to WSWindowFrame.
  594. window.frame().on_mouse_event(event.translated(-window_frame_rect.location()));
  595. event_window_with_frame = &window;
  596. return IterationDecision::Abort;
  597. });
  598. if (event_window_with_frame != m_resize_candidate.ptr())
  599. clear_resize_candidate();
  600. }
  601. void WSWindowManager::clear_resize_candidate()
  602. {
  603. if (m_resize_candidate)
  604. invalidate_cursor();
  605. m_resize_candidate = nullptr;
  606. }
  607. bool WSWindowManager::any_opaque_window_contains_rect(const Rect& rect)
  608. {
  609. bool found_containing_window = false;
  610. for_each_window([&] (WSWindow& window) {
  611. if (!window.is_visible())
  612. return IterationDecision::Continue;
  613. if (window.is_minimized())
  614. return IterationDecision::Continue;
  615. if (window.opacity() < 1.0f)
  616. return IterationDecision::Continue;
  617. if (window.has_alpha_channel()) {
  618. // FIXME: Just because the window has an alpha channel doesn't mean it's not opaque.
  619. // Maybe there's some way we could know this?
  620. return IterationDecision::Continue;
  621. }
  622. if (window.frame().rect().contains(rect)) {
  623. found_containing_window = true;
  624. return IterationDecision::Abort;
  625. }
  626. return IterationDecision::Continue;
  627. });
  628. return found_containing_window;
  629. };
  630. bool WSWindowManager::any_opaque_window_above_this_one_contains_rect(const WSWindow& a_window, const Rect& rect)
  631. {
  632. bool found_containing_window = false;
  633. bool checking = false;
  634. for_each_visible_window_from_back_to_front([&] (WSWindow& window) {
  635. if (&window == &a_window) {
  636. checking = true;
  637. return IterationDecision::Continue;
  638. }
  639. if (!checking)
  640. return IterationDecision::Continue;
  641. if (!window.is_visible())
  642. return IterationDecision::Continue;
  643. if (window.is_minimized())
  644. return IterationDecision::Continue;
  645. if (window.opacity() < 1.0f)
  646. return IterationDecision::Continue;
  647. if (window.has_alpha_channel())
  648. return IterationDecision::Continue;
  649. if (window.frame().rect().contains(rect)) {
  650. found_containing_window = true;
  651. return IterationDecision::Abort;
  652. }
  653. return IterationDecision::Continue;
  654. });
  655. return found_containing_window;
  656. };
  657. void WSWindowManager::compose()
  658. {
  659. auto dirty_rects = move(m_dirty_rects);
  660. dirty_rects.add(Rect::intersection(m_last_geometry_label_rect, m_screen_rect));
  661. dirty_rects.add(Rect::intersection(m_last_cursor_rect, m_screen_rect));
  662. dirty_rects.add(Rect::intersection(current_cursor_rect(), m_screen_rect));
  663. #ifdef DEBUG_COUNTERS
  664. dbgprintf("[WM] compose #%u (%u rects)\n", ++m_compose_count, dirty_rects.rects().size());
  665. #endif
  666. auto any_dirty_rect_intersects_window = [&dirty_rects] (const WSWindow& window) {
  667. auto window_frame_rect = window.frame().rect();
  668. for (auto& dirty_rect : dirty_rects.rects()) {
  669. if (dirty_rect.intersects(window_frame_rect))
  670. return true;
  671. }
  672. return false;
  673. };
  674. for (auto& dirty_rect : dirty_rects.rects()) {
  675. if (any_opaque_window_contains_rect(dirty_rect))
  676. continue;
  677. if (!m_wallpaper)
  678. m_back_painter->fill_rect(dirty_rect, m_background_color);
  679. else
  680. m_back_painter->blit(dirty_rect.location(), *m_wallpaper, dirty_rect);
  681. }
  682. for_each_visible_window_from_back_to_front([&] (WSWindow& window) {
  683. if (!any_dirty_rect_intersects_window(window))
  684. return IterationDecision::Continue;
  685. PainterStateSaver saver(*m_back_painter);
  686. m_back_painter->add_clip_rect(window.frame().rect());
  687. RetainPtr<GraphicsBitmap> backing_store = window.backing_store();
  688. for (auto& dirty_rect : dirty_rects.rects()) {
  689. if (any_opaque_window_above_this_one_contains_rect(window, dirty_rect))
  690. continue;
  691. PainterStateSaver saver(*m_back_painter);
  692. m_back_painter->add_clip_rect(dirty_rect);
  693. window.frame().paint(*m_back_painter);
  694. if (!backing_store)
  695. continue;
  696. Rect dirty_rect_in_window_coordinates = Rect::intersection(dirty_rect, window.rect());
  697. if (dirty_rect_in_window_coordinates.is_empty())
  698. continue;
  699. dirty_rect_in_window_coordinates.move_by(-window.position());
  700. auto dst = window.position();
  701. dst.move_by(dirty_rect_in_window_coordinates.location());
  702. m_back_painter->blit(dst, *backing_store, dirty_rect_in_window_coordinates, window.opacity());
  703. if (backing_store->width() < window.width()) {
  704. Rect right_fill_rect { window.x() + backing_store->width(), window.y(), window.width() - backing_store->width(), window.height() };
  705. m_back_painter->fill_rect(right_fill_rect, window.background_color());
  706. }
  707. if (backing_store->height() < window.height()) {
  708. Rect bottom_fill_rect { window.x(), window.y() + backing_store->height(), window.width(), window.height() - backing_store->height() };
  709. m_back_painter->fill_rect(bottom_fill_rect, window.background_color());
  710. }
  711. }
  712. return IterationDecision::Continue;
  713. });
  714. draw_geometry_label();
  715. draw_menubar();
  716. draw_cursor();
  717. if (m_flash_flush) {
  718. for (auto& rect : dirty_rects.rects())
  719. m_front_painter->fill_rect(rect, Color::Yellow);
  720. }
  721. flip_buffers();
  722. for (auto& r : dirty_rects.rects())
  723. flush(r);
  724. }
  725. Rect WSWindowManager::current_cursor_rect() const
  726. {
  727. return { m_screen.cursor_location().translated(-active_cursor().hotspot()), active_cursor().size() };
  728. }
  729. void WSWindowManager::invalidate_cursor()
  730. {
  731. invalidate(current_cursor_rect());
  732. }
  733. Rect WSWindowManager::menubar_rect() const
  734. {
  735. return { 0, 0, m_screen_rect.width(), 18 };
  736. }
  737. void WSWindowManager::draw_menubar()
  738. {
  739. auto menubar_rect = this->menubar_rect();
  740. m_back_painter->fill_rect(menubar_rect, Color::LightGray);
  741. m_back_painter->draw_line({ 0, menubar_rect.bottom() }, { menubar_rect.right(), menubar_rect.bottom() }, Color::MidGray);
  742. int index = 0;
  743. for_each_active_menubar_menu([&] (WSMenu& menu) {
  744. Color text_color = Color::Black;
  745. if (&menu == current_menu()) {
  746. m_back_painter->fill_rect(menu.rect_in_menubar(), menu_selection_color());
  747. text_color = Color::White;
  748. }
  749. m_back_painter->draw_text(
  750. menu.text_rect_in_menubar(),
  751. menu.name(),
  752. index == 1 ? app_menu_font() : menu_font(),
  753. TextAlignment::CenterLeft,
  754. text_color
  755. );
  756. ++index;
  757. return true;
  758. });
  759. int username_width = Font::default_bold_font().width(m_username);
  760. Rect username_rect {
  761. menubar_rect.right() - menubar_menu_margin() / 2 - Font::default_bold_font().width(m_username),
  762. menubar_rect.y(),
  763. username_width,
  764. menubar_rect.height()
  765. };
  766. m_back_painter->draw_text(username_rect, m_username, Font::default_bold_font(), TextAlignment::CenterRight, Color::Black);
  767. time_t now = time(nullptr);
  768. auto* tm = localtime(&now);
  769. auto time_text = String::format("%4u-%02u-%02u %02u:%02u:%02u",
  770. tm->tm_year + 1900,
  771. tm->tm_mon + 1,
  772. tm->tm_mday,
  773. tm->tm_hour,
  774. tm->tm_min,
  775. tm->tm_sec);
  776. int time_width = font().width(time_text);
  777. Rect time_rect {
  778. username_rect.left() - menubar_menu_margin() / 2 - time_width,
  779. menubar_rect.y(),
  780. time_width,
  781. menubar_rect.height()
  782. };
  783. m_back_painter->draw_text(time_rect, time_text, font(), TextAlignment::CenterRight, Color::Black);
  784. Rect cpu_rect { time_rect.right() - font().width(time_text) - m_cpu_monitor.capacity() - 10, time_rect.y() + 1, m_cpu_monitor.capacity(), time_rect.height() - 2 };
  785. m_cpu_monitor.paint(*m_back_painter, cpu_rect);
  786. }
  787. void WSWindowManager::draw_window_switcher()
  788. {
  789. if (m_switcher.is_visible())
  790. m_switcher.draw();
  791. }
  792. void WSWindowManager::draw_geometry_label()
  793. {
  794. auto* window_being_moved_or_resized = m_drag_window ? m_drag_window.ptr() : (m_resize_window ? m_resize_window.ptr() : nullptr);
  795. if (!window_being_moved_or_resized) {
  796. m_last_geometry_label_rect = { };
  797. return;
  798. }
  799. auto geometry_string = window_being_moved_or_resized->rect().to_string();
  800. if (!window_being_moved_or_resized->size_increment().is_null()) {
  801. int width_steps = (window_being_moved_or_resized->width() - window_being_moved_or_resized->base_size().width()) / window_being_moved_or_resized->size_increment().width();
  802. int height_steps = (window_being_moved_or_resized->height() - window_being_moved_or_resized->base_size().height()) / window_being_moved_or_resized->size_increment().height();
  803. geometry_string = String::format("%s (%dx%d)", geometry_string.characters(), width_steps, height_steps);
  804. }
  805. auto geometry_label_rect = Rect { 0, 0, font().width(geometry_string) + 16, font().glyph_height() + 10 };
  806. geometry_label_rect.center_within(window_being_moved_or_resized->rect());
  807. m_back_painter->fill_rect(geometry_label_rect, Color::LightGray);
  808. m_back_painter->draw_rect(geometry_label_rect, Color::DarkGray);
  809. m_back_painter->draw_text(geometry_label_rect, geometry_string, TextAlignment::Center);
  810. m_last_geometry_label_rect = geometry_label_rect;
  811. }
  812. void WSWindowManager::draw_cursor()
  813. {
  814. Rect cursor_rect = current_cursor_rect();
  815. Color inner_color = Color::White;
  816. Color outer_color = Color::Black;
  817. if (m_screen.mouse_button_state() & (unsigned)MouseButton::Left)
  818. swap(inner_color, outer_color);
  819. m_back_painter->blit(cursor_rect.location(), active_cursor().bitmap(), active_cursor().rect());
  820. m_last_cursor_rect = cursor_rect;
  821. }
  822. void WSWindowManager::event(CEvent& event)
  823. {
  824. if (static_cast<WSEvent&>(event).is_mouse_event()) {
  825. WSWindow* event_window = nullptr;
  826. process_mouse_event(static_cast<const WSMouseEvent&>(event), event_window);
  827. set_hovered_window(event_window);
  828. return;
  829. }
  830. if (static_cast<WSEvent&>(event).is_key_event()) {
  831. auto& key_event = static_cast<const WSKeyEvent&>(event);
  832. m_keyboard_modifiers = key_event.modifiers();
  833. if (key_event.type() == WSEvent::KeyDown && key_event.modifiers() == Mod_Logo && key_event.key() == Key_Tab)
  834. m_switcher.show();
  835. if (m_switcher.is_visible()) {
  836. m_switcher.on_key_event(key_event);
  837. return;
  838. }
  839. if (m_active_window)
  840. return m_active_window->event(event);
  841. return;
  842. }
  843. if (event.type() == WSEvent::WM_DeferredCompose) {
  844. m_pending_compose_event = false;
  845. compose();
  846. return;
  847. }
  848. }
  849. void WSWindowManager::set_highlight_window(WSWindow* window)
  850. {
  851. if (window == m_highlight_window)
  852. return;
  853. if (auto* previous_highlight_window = m_highlight_window.ptr())
  854. invalidate(*previous_highlight_window);
  855. m_highlight_window = window ? window->make_weak_ptr() : nullptr;
  856. if (m_highlight_window)
  857. invalidate(*m_highlight_window);
  858. }
  859. void WSWindowManager::set_active_window(WSWindow* window)
  860. {
  861. if (window && window->is_blocked_by_modal_window())
  862. return;
  863. if (window->type() != WSWindowType::Normal) {
  864. dbgprintf("WSWindowManager: Attempted to make a non-normal window active.\n");
  865. return;
  866. }
  867. if (window == m_active_window)
  868. return;
  869. auto* previously_active_window = m_active_window.ptr();
  870. if (previously_active_window) {
  871. WSEventLoop::the().post_event(*previously_active_window, make<WSEvent>(WSEvent::WindowDeactivated));
  872. invalidate(*previously_active_window);
  873. }
  874. m_active_window = window->make_weak_ptr();
  875. if (m_active_window) {
  876. WSEventLoop::the().post_event(*m_active_window, make<WSEvent>(WSEvent::WindowActivated));
  877. invalidate(*m_active_window);
  878. auto* client = window->client();
  879. ASSERT(client);
  880. set_current_menubar(client->app_menubar());
  881. if (previously_active_window)
  882. tell_wm_listeners_window_state_changed(*previously_active_window);
  883. tell_wm_listeners_window_state_changed(*m_active_window);
  884. }
  885. }
  886. void WSWindowManager::set_hovered_window(WSWindow* window)
  887. {
  888. if (m_hovered_window == window)
  889. return;
  890. if (m_hovered_window)
  891. WSEventLoop::the().post_event(*m_hovered_window, make<WSEvent>(WSEvent::WindowLeft));
  892. m_hovered_window = window ? window->make_weak_ptr() : nullptr;
  893. if (m_hovered_window)
  894. WSEventLoop::the().post_event(*m_hovered_window, make<WSEvent>(WSEvent::WindowEntered));
  895. }
  896. void WSWindowManager::invalidate()
  897. {
  898. m_dirty_rects.clear_with_capacity();
  899. invalidate(m_screen_rect);
  900. }
  901. void WSWindowManager::recompose_immediately()
  902. {
  903. m_dirty_rects.clear_with_capacity();
  904. invalidate(m_screen_rect, false);
  905. }
  906. void WSWindowManager::invalidate(const Rect& a_rect, bool should_schedule_compose_event)
  907. {
  908. auto rect = Rect::intersection(a_rect, m_screen_rect);
  909. if (rect.is_empty())
  910. return;
  911. m_dirty_rects.add(rect);
  912. if (should_schedule_compose_event && !m_pending_compose_event) {
  913. WSEventLoop::the().post_event(*this, make<WSEvent>(WSEvent::WM_DeferredCompose));
  914. m_pending_compose_event = true;
  915. }
  916. }
  917. void WSWindowManager::invalidate(const WSWindow& window)
  918. {
  919. invalidate(window.frame().rect());
  920. }
  921. void WSWindowManager::invalidate(const WSWindow& window, const Rect& rect)
  922. {
  923. if (rect.is_empty()) {
  924. invalidate(window);
  925. return;
  926. }
  927. auto outer_rect = window.frame().rect();
  928. auto inner_rect = rect;
  929. inner_rect.move_by(window.position());
  930. // FIXME: This seems slightly wrong; the inner rect shouldn't intersect the border part of the outer rect.
  931. inner_rect.intersect(outer_rect);
  932. invalidate(inner_rect);
  933. }
  934. void WSWindowManager::flush(const Rect& a_rect)
  935. {
  936. auto rect = Rect::intersection(a_rect, m_screen_rect);
  937. #ifdef DEBUG_COUNTERS
  938. dbgprintf("[WM] flush #%u (%d,%d %dx%d)\n", ++m_flush_count, rect.x(), rect.y(), rect.width(), rect.height());
  939. #endif
  940. const RGBA32* front_ptr = m_front_bitmap->scanline(rect.y()) + rect.x();
  941. RGBA32* back_ptr = m_back_bitmap->scanline(rect.y()) + rect.x();
  942. size_t pitch = m_back_bitmap->pitch();
  943. for (int y = 0; y < rect.height(); ++y) {
  944. fast_dword_copy(back_ptr, front_ptr, rect.width());
  945. front_ptr = (const RGBA32*)((const byte*)front_ptr + pitch);
  946. back_ptr = (RGBA32*)((byte*)back_ptr + pitch);
  947. }
  948. }
  949. void WSWindowManager::close_menu(WSMenu& menu)
  950. {
  951. if (current_menu() == &menu)
  952. close_current_menu();
  953. }
  954. void WSWindowManager::close_menubar(WSMenuBar& menubar)
  955. {
  956. if (current_menubar() == &menubar)
  957. set_current_menubar(nullptr);
  958. }
  959. const WSClientConnection* WSWindowManager::active_client() const
  960. {
  961. if (m_active_window)
  962. return m_active_window->client();
  963. return nullptr;
  964. }
  965. void WSWindowManager::notify_client_changed_app_menubar(WSClientConnection& client)
  966. {
  967. if (active_client() == &client)
  968. set_current_menubar(client.app_menubar());
  969. invalidate(menubar_rect());
  970. }
  971. const WSCursor& WSWindowManager::active_cursor() const
  972. {
  973. if (m_drag_window)
  974. return *m_move_cursor;
  975. if (m_resize_window || m_resize_candidate) {
  976. switch (m_resize_direction) {
  977. case ResizeDirection::Up:
  978. case ResizeDirection::Down:
  979. return *m_resize_vertically_cursor;
  980. case ResizeDirection::Left:
  981. case ResizeDirection::Right:
  982. return *m_resize_horizontally_cursor;
  983. case ResizeDirection::UpLeft:
  984. case ResizeDirection::DownRight:
  985. return *m_resize_diagonally_tlbr_cursor;
  986. case ResizeDirection::UpRight:
  987. case ResizeDirection::DownLeft:
  988. return *m_resize_diagonally_bltr_cursor;
  989. case ResizeDirection::None:
  990. break;
  991. }
  992. }
  993. if (m_hovered_window && m_hovered_window->override_cursor())
  994. return *m_hovered_window->override_cursor();
  995. return *m_arrow_cursor;
  996. }
  997. void WSWindowManager::set_hovered_button(WSButton* button)
  998. {
  999. m_hovered_button = button ? button->make_weak_ptr() : nullptr;
  1000. }
  1001. void WSWindowManager::set_resize_candidate(WSWindow& window, ResizeDirection direction)
  1002. {
  1003. m_resize_candidate = window.make_weak_ptr();
  1004. m_resize_direction = direction;
  1005. }