Changeset acd7ac2 in mainline


Ignore:
Timestamp:
2023-08-09T11:27:03Z (9 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
24be331e
Parents:
a77c722
git-author:
Jiri Svoboda <jiri@…> (2023-08-08 17:26:15)
git-committer:
Jiri Svoboda <jiri@…> (2023-08-09 11:27:03)
Message:

Switch focus to the right window when window is closed

Location:
uspace/srv/hid/display
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/seat.c

    ra77c722 racd7ac2  
    204204
    205205        /* Find alternate window that is neither system nor minimized */
    206         nwnd = ds_window_find_alt(wnd, ~(wndf_minimized | wndf_system));
     206        nwnd = ds_window_find_prev(wnd, ~(wndf_minimized | wndf_system));
    207207
    208208        if (nwnd == NULL) {
    209209                /* Find alternate window that is not minimized */
    210                 nwnd = ds_window_find_alt(wnd, ~wndf_minimized);
     210                nwnd = ds_window_find_prev(wnd, ~wndf_minimized);
    211211        }
    212212
     
    224224
    225225        /* Find alternate window that is not a system window */
    226         nwnd = ds_window_find_alt(seat->focus, ~wndf_system);
     226        nwnd = ds_window_find_next(seat->focus, ~wndf_system);
    227227
    228228        /* Only switch focus if there is another window */
  • uspace/srv/hid/display/test/seat.c

    ra77c722 racd7ac2  
    212212        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    213213
     214        /* w0 is at the top, then w1, then w2 */
     215
    214216        PCUT_ASSERT_EQUALS(w0, seat->focus);
    215217
    216218        ds_window_unfocus(w0);
    217219
    218         /* The previous window, w2, should be focused now */
    219         PCUT_ASSERT_EQUALS(w2, seat->focus);
     220        /* The previous window, w1, should be focused now */
     221        PCUT_ASSERT_EQUALS(w1, seat->focus);
    220222
    221223        ds_window_destroy(w0);
  • uspace/srv/hid/display/test/window.c

    ra77c722 racd7ac2  
    11691169}
    11701170
    1171 /** ds_window_find_alt() finds alternate window by flags */
    1172 PCUT_TEST(window_find_alt)
     1171/** ds_window_find_next() finds next window by flags */
     1172PCUT_TEST(window_find_next)
    11731173{
    11741174        gfx_context_t *gc;
     
    12101210        w2->flags |= wndf_system;
    12111211
    1212         wnd = ds_window_find_alt(w0, wndf_minimized);
     1212        wnd = ds_window_find_next(w0, wndf_minimized);
    12131213        PCUT_ASSERT_EQUALS(w1, wnd);
    12141214
    1215         wnd = ds_window_find_alt(w0, wndf_system);
     1215        wnd = ds_window_find_next(w0, wndf_system);
    12161216        PCUT_ASSERT_EQUALS(w2, wnd);
    12171217
    1218         wnd = ds_window_find_alt(w0, wndf_maximized);
     1218        wnd = ds_window_find_next(w0, wndf_maximized);
     1219        PCUT_ASSERT_NULL(wnd);
     1220
     1221        ds_window_destroy(w0);
     1222        ds_window_destroy(w1);
     1223        ds_window_destroy(w2);
     1224        ds_seat_destroy(seat);
     1225        ds_client_destroy(client);
     1226        ds_display_destroy(disp);
     1227}
     1228
     1229/** ds_window_find_prev() finds previous window by flags */
     1230PCUT_TEST(window_find_prev)
     1231{
     1232        gfx_context_t *gc;
     1233        ds_display_t *disp;
     1234        ds_client_t *client;
     1235        ds_seat_t *seat;
     1236        ds_window_t *w0;
     1237        ds_window_t *w1;
     1238        ds_window_t *w2;
     1239        ds_window_t *wnd;
     1240        display_wnd_params_t params;
     1241        errno_t rc;
     1242
     1243        rc = gfx_context_new(&dummy_ops, NULL, &gc);
     1244        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1245
     1246        rc = ds_display_create(gc, df_none, &disp);
     1247        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1248
     1249        rc = ds_client_create(disp, NULL, NULL, &client);
     1250        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1251
     1252        rc = ds_seat_create(disp, "Alice", &seat);
     1253        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1254
     1255        display_wnd_params_init(&params);
     1256        params.rect.p0.x = params.rect.p0.y = 0;
     1257        params.rect.p1.x = params.rect.p1.y = 1;
     1258
     1259        rc = ds_window_create(client, &params, &w2);
     1260        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1261        w2->flags |= wndf_system;
     1262
     1263        rc = ds_window_create(client, &params, &w1);
     1264        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1265        w1->flags |= wndf_minimized;
     1266
     1267        rc = ds_window_create(client, &params, &w0);
     1268        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1269
     1270        wnd = ds_window_find_prev(w0, wndf_minimized);
     1271        PCUT_ASSERT_EQUALS(w1, wnd);
     1272
     1273        wnd = ds_window_find_prev(w0, wndf_system);
     1274        PCUT_ASSERT_EQUALS(w2, wnd);
     1275
     1276        wnd = ds_window_find_prev(w0, wndf_maximized);
    12191277        PCUT_ASSERT_NULL(wnd);
    12201278
  • uspace/srv/hid/display/window.c

    ra77c722 racd7ac2  
    10921092 * @return Alternate window matching the criteria or @c NULL if there is none
    10931093 */
    1094 ds_window_t *ds_window_find_alt(ds_window_t *wnd,
     1094ds_window_t *ds_window_find_prev(ds_window_t *wnd,
     1095    display_wnd_flags_t allowed_flags)
     1096{
     1097        ds_window_t *nwnd;
     1098
     1099        /* Try preceding windows in display order */
     1100        nwnd = ds_display_next_window(wnd);
     1101        while (nwnd != NULL && (nwnd->flags & ~allowed_flags) != 0) {
     1102                nwnd = ds_display_next_window(nwnd);
     1103        }
     1104
     1105        /* Do we already have a matching window? */
     1106        if (nwnd != NULL && (nwnd->flags & ~allowed_flags) == 0) {
     1107                return nwnd;
     1108        }
     1109
     1110        /* Try succeeding windows in display order */
     1111        nwnd = ds_display_first_window(wnd->display);
     1112        while (nwnd != NULL && nwnd != wnd &&
     1113            (nwnd->flags & ~allowed_flags) != 0) {
     1114                nwnd = ds_display_next_window(nwnd);
     1115        }
     1116
     1117        if (nwnd == wnd)
     1118                return NULL;
     1119
     1120        return nwnd;
     1121}
     1122
     1123/** Find alternate window with the allowed flags.
     1124 *
     1125 * An alternate window is a *different* window that is preferably previous
     1126 * in the display order and only has the @a allowed flags.
     1127 *
     1128 * @param wnd Window
     1129 * @param allowed_flags Bitmask of flags that the window is allowed to have
     1130 *
     1131 * @return Alternate window matching the criteria or @c NULL if there is none
     1132 */
     1133ds_window_t *ds_window_find_next(ds_window_t *wnd,
    10951134    display_wnd_flags_t allowed_flags)
    10961135{
  • uspace/srv/hid/display/window.h

    ra77c722 racd7ac2  
    7878extern errno_t ds_window_set_cursor(ds_window_t *, display_stock_cursor_t);
    7979extern errno_t ds_window_set_caption(ds_window_t *, const char *);
    80 extern ds_window_t *ds_window_find_alt(ds_window_t *, display_wnd_flags_t);
     80extern ds_window_t *ds_window_find_next(ds_window_t *, display_wnd_flags_t);
     81extern ds_window_t *ds_window_find_prev(ds_window_t *, display_wnd_flags_t);
    8182extern void ds_window_unfocus(ds_window_t *);
    8283extern bool ds_window_orig_seat(ds_window_t *, sysarg_t);
Note: See TracChangeset for help on using the changeset viewer.