0002-Accept-window-positon-parameters-over-wayland-in-des.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. From 0dc3250366ff8ef7f1a5201f4186e3617caa0e04 Mon Sep 17 00:00:00 2001
  2. From: Yugang <fanyugang.fyg@linux.alibaba.com>
  3. Date: Fri, 17 Jun 2022 12:08:41 +0800
  4. Subject: [PATCH 2/2] Accept window positon parameters over wayland in desktop
  5. shell.
  6. ---
  7. desktop-shell/shell.c | 46 +++++++++++++++++++++++------------
  8. libweston-desktop/xdg-shell.c | 4 +--
  9. 2 files changed, 33 insertions(+), 17 deletions(-)
  10. diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
  11. index c1c126e8..f9d7e925 100644
  12. --- a/desktop-shell/shell.c
  13. +++ b/desktop-shell/shell.c
  14. @@ -1998,8 +1998,7 @@ shell_surface_set_output(struct shell_surface *shsurf,
  15. }
  16. static void
  17. -weston_view_set_initial_position(struct weston_view *view,
  18. - struct desktop_shell *shell);
  19. +weston_view_set_initial_position(struct shell_surface *shsurf);
  20. static void
  21. unset_fullscreen(struct shell_surface *shsurf)
  22. @@ -2016,7 +2015,7 @@ unset_fullscreen(struct shell_surface *shsurf)
  23. weston_view_set_position(shsurf->view,
  24. shsurf->saved_x, shsurf->saved_y);
  25. else
  26. - weston_view_set_initial_position(shsurf->view, shsurf->shell);
  27. + weston_view_set_initial_position(shsurf);
  28. shsurf->saved_position_valid = false;
  29. if (shsurf->saved_rotation_valid) {
  30. @@ -2039,7 +2038,7 @@ unset_maximized(struct shell_surface *shsurf)
  31. weston_view_set_position(shsurf->view,
  32. shsurf->saved_x, shsurf->saved_y);
  33. else
  34. - weston_view_set_initial_position(shsurf->view, shsurf->shell);
  35. + weston_view_set_initial_position(shsurf);
  36. shsurf->saved_position_valid = false;
  37. if (shsurf->saved_rotation_valid) {
  38. @@ -2535,7 +2534,7 @@ map(struct desktop_shell *shell, struct shell_surface *shsurf,
  39. } else if (shsurf->xwayland.is_set) {
  40. set_position_from_xwayland(shsurf);
  41. } else {
  42. - weston_view_set_initial_position(shsurf->view, shell);
  43. + weston_view_set_initial_position(shsurf);
  44. }
  45. /* Surface stacking order, see also activate(). */
  46. @@ -4284,9 +4283,10 @@ center_on_output(struct weston_view *view, struct weston_output *output)
  47. }
  48. static void
  49. -weston_view_set_initial_position(struct weston_view *view,
  50. - struct desktop_shell *shell)
  51. +weston_view_set_initial_position(struct shell_surface *shsurf)
  52. {
  53. + struct weston_view *view = shsurf->view;
  54. + struct desktop_shell *shell = shsurf->shell;
  55. struct weston_compositor *compositor = shell->compositor;
  56. int ix = 0, iy = 0;
  57. int32_t range_x, range_y;
  58. @@ -4294,6 +4294,11 @@ weston_view_set_initial_position(struct weston_view *view,
  59. struct weston_output *output, *target_output = NULL;
  60. struct weston_seat *seat;
  61. pixman_rectangle32_t area;
  62. + const char *thead_window_position;
  63. +
  64. + /* T-HEAD: Use ENV to support window position set */
  65. + struct weston_geometry geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface);
  66. + thead_window_position = getenv("THEAD_WINDOW_POSITION");
  67. /* As a heuristic place the new window on the same output as the
  68. * pointer. Falling back to the output containing 0, 0.
  69. @@ -4318,8 +4323,13 @@ weston_view_set_initial_position(struct weston_view *view,
  70. }
  71. if (!target_output) {
  72. - weston_view_set_position(view, 10 + random() % 400,
  73. + if (thead_window_position && !strcmp(thead_window_position, "true")) {
  74. + weston_log("Enabled Thead window move\n");
  75. + weston_view_set_position(view, geometry.x, geometry.y);
  76. + } else {
  77. + weston_view_set_position(view, 10 + random() % 400,
  78. 10 + random() % 400);
  79. + }
  80. return;
  81. }
  82. @@ -4331,16 +4341,22 @@ weston_view_set_initial_position(struct weston_view *view,
  83. x = area.x;
  84. y = area.y;
  85. - range_x = area.width - view->surface->width;
  86. - range_y = area.height - view->surface->height;
  87. - if (range_x > 0)
  88. - x += random() % range_x;
  89. + if (thead_window_position && !strcmp(thead_window_position, "true")) {
  90. + weston_log("Enabled Thead window move for target output\n");
  91. + weston_view_set_position(view, x + geometry.x, y + geometry.y);
  92. + } else {
  93. + range_x = area.width - view->surface->width;
  94. + range_y = area.height - view->surface->height;
  95. - if (range_y > 0)
  96. - y += random() % range_y;
  97. + if (range_x > 0)
  98. + x += random() % range_x;
  99. - weston_view_set_position(view, x, y);
  100. + if (range_y > 0)
  101. + y += random() % range_y;
  102. +
  103. + weston_view_set_position(view, x, y);
  104. + }
  105. }
  106. static bool
  107. diff --git a/libweston-desktop/xdg-shell.c b/libweston-desktop/xdg-shell.c
  108. index 4a9eb977..aef02c03 100644
  109. --- a/libweston-desktop/xdg-shell.c
  110. +++ b/libweston-desktop/xdg-shell.c
  111. @@ -672,7 +672,7 @@ weston_desktop_xdg_toplevel_committed(struct weston_desktop_xdg_toplevel *toplev
  112. struct weston_geometry geometry =
  113. weston_desktop_surface_get_geometry(toplevel->base.desktop_surface);
  114. -
  115. +/*
  116. if (toplevel->next.state.maximized &&
  117. (toplevel->next.size.width != geometry.width ||
  118. toplevel->next.size.height != geometry.height)) {
  119. @@ -708,7 +708,7 @@ weston_desktop_xdg_toplevel_committed(struct weston_desktop_xdg_toplevel *toplev
  120. toplevel->next.size.height);
  121. return;
  122. }
  123. -
  124. +*/
  125. toplevel->current.state = toplevel->next.state;
  126. toplevel->current.min_size = toplevel->next.min_size;
  127. toplevel->current.max_size = toplevel->next.max_size;
  128. --
  129. 2.17.1