Changeset f1f433d in mainline


Ignore:
Timestamp:
2022-11-04T20:54:04Z (2 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3a6d44b7
Parents:
fc00f0d
Message:

Update window button when window caption changes

Location:
uspace
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/taskbar/wndlist.c

    rfc00f0d rf1f433d  
    4848static void wndlist_wm_window_added(void *, sysarg_t);
    4949static void wndlist_wm_window_removed(void *, sysarg_t);
     50static void wndlist_wm_window_changed(void *, sysarg_t);
    5051
    5152static wndmgt_cb_t wndlist_wndmgt_cb = {
    5253        .window_added = wndlist_wm_window_added,
    53         .window_removed = wndlist_wm_window_removed
     54        .window_removed = wndlist_wm_window_removed,
     55        .window_changed = wndlist_wm_window_changed
    5456};
    5557
     
    233235        if (!paint)
    234236                return EOK;
     237
     238        return wndlist_repaint(wndlist);
     239}
     240
     241/** Update window list entry.
     242 *
     243 * @param wndlist Window list
     244 * @param entry Window list entry
     245 * @return @c EOK on success or an error code
     246 */
     247errno_t wndlist_update(wndlist_t *wndlist, wndlist_entry_t *entry,
     248    const char *caption)
     249{
     250        errno_t rc;
     251        assert(entry->wndlist == wndlist);
     252
     253        rc = ui_pbutton_set_caption(entry->button, caption);
     254        if (rc != EOK)
     255                return rc;
     256
     257        rc = ui_pbutton_paint(entry->button);
     258        if (rc != EOK)
     259                return rc;
    235260
    236261        return wndlist_repaint(wndlist);
     
    325350}
    326351
     352/** Handle WM window changed event.
     353 *
     354 * @param arg Argument (wndlist_t *)
     355 * @param wnd_id Window ID
     356 */
     357static void wndlist_wm_window_changed(void *arg, sysarg_t wnd_id)
     358{
     359        wndlist_t *wndlist = (wndlist_t *)arg;
     360        wndmgt_window_info_t *winfo = NULL;
     361        wndlist_entry_t *entry;
     362        errno_t rc;
     363
     364        printf("wm_window_changed: wndlist=%p wnd_id=%zu\n",
     365            (void *)wndlist, wnd_id);
     366
     367        entry = wndlist_entry_by_id(wndlist, wnd_id);
     368        if (entry == NULL)
     369                return;
     370
     371        rc = wndmgt_get_window_info(wndlist->wndmgt, wnd_id, &winfo);
     372        if (rc != EOK)
     373                return;
     374
     375        (void) wndlist_update(wndlist, entry, winfo->caption);
     376        wndmgt_free_window_info(winfo);
     377}
     378
    327379/** Find window list entry by ID.
    328380 *
  • uspace/app/taskbar/wndlist.h

    rfc00f0d rf1f433d  
    4949extern errno_t wndlist_append(wndlist_t *, sysarg_t, const char *, bool);
    5050extern errno_t wndlist_remove(wndlist_t *, wndlist_entry_t *, bool);
     51extern errno_t wndlist_update(wndlist_t *, wndlist_entry_t *, const char *);
    5152extern void wndlist_set_entry_rect(wndlist_t *, wndlist_entry_t *);
    5253extern wndlist_entry_t *wndlist_entry_by_id(wndlist_t *, sysarg_t);
  • uspace/lib/ui/include/ui/pbutton.h

    rfc00f0d rf1f433d  
    5656extern void ui_pbutton_set_rect(ui_pbutton_t *, gfx_rect_t *);
    5757extern void ui_pbutton_set_default(ui_pbutton_t *, bool);
     58extern errno_t ui_pbutton_set_caption(ui_pbutton_t *, const char *);
    5859extern errno_t ui_pbutton_paint(ui_pbutton_t *);
    5960extern void ui_pbutton_press(ui_pbutton_t *);
  • uspace/lib/ui/private/pbutton.h

    rfc00f0d rf1f433d  
    6262        gfx_rect_t rect;
    6363        /** Caption */
    64         const char *caption;
     64        char *caption;
    6565        /** Button is selected as default */
    6666        bool isdefault;
  • uspace/lib/ui/src/pbutton.c

    rfc00f0d rf1f433d  
    114114
    115115        ui_control_delete(pbutton->control);
     116        free(pbutton->caption);
    116117        free(pbutton);
    117118}
     
    183184{
    184185        pbutton->isdefault = isdefault;
     186}
     187
     188/** Set push button caption.
     189 *
     190 * @param pbutton Button
     191 * @param caption New caption
     192 * @return EOK on success, ENOMEM if out of memory
     193 */
     194errno_t ui_pbutton_set_caption(ui_pbutton_t *pbutton, const char *caption)
     195{
     196        char *dcaption;
     197
     198        dcaption = str_dup(caption);
     199        if (dcaption == NULL)
     200                return ENOMEM;
     201
     202        free(pbutton->caption);
     203        pbutton->caption = dcaption;
     204        return EOK;
    185205}
    186206
  • uspace/lib/ui/test/pbutton.c

    rfc00f0d rf1f433d  
    190190}
    191191
     192/** Set caption sets internal field */
     193PCUT_TEST(set_caption)
     194{
     195        ui_pbutton_t *pbutton;
     196        errno_t rc;
     197
     198        rc = ui_pbutton_create(NULL, "Hello", &pbutton);
     199        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     200
     201        PCUT_ASSERT_STR_EQUALS("Hello", pbutton->caption);
     202
     203        rc = ui_pbutton_set_caption(pbutton, "World");
     204        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     205
     206        PCUT_ASSERT_STR_EQUALS("World", pbutton->caption);
     207
     208        ui_pbutton_destroy(pbutton);
     209}
     210
    192211/** Paint button */
    193212PCUT_TEST(paint)
  • uspace/lib/wndmgt/include/types/wndmgt.h

    rfc00f0d rf1f433d  
    5353        /** Window removed */
    5454        void (*window_removed)(void *, sysarg_t);
     55        /** Window changed */
     56        void (*window_changed)(void *, sysarg_t);
    5557} wndmgt_cb_t;
    5658
     
    6062        wmev_window_added,
    6163        /** Window removed */
    62         wmev_window_removed
     64        wmev_window_removed,
     65        /** Window changed */
     66        wmev_window_changed
    6367} wndmgt_ev_type_t;
    6468
  • uspace/lib/wndmgt/src/wndmgt.c

    rfc00f0d rf1f433d  
    387387                        }
    388388                        break;
     389                case wmev_window_changed:
     390                        if (wndmgt->cb != NULL &&
     391                            wndmgt->cb->window_changed != NULL) {
     392                                wndmgt->cb->window_changed(wndmgt->cb_arg,
     393                                    event.wnd_id);
     394                        }
     395                        break;
    389396                }
    390397        }
  • uspace/lib/wndmgt/test/wndmgt.c

    rfc00f0d rf1f433d  
    5454static void test_window_added(void *, sysarg_t);
    5555static void test_window_removed(void *, sysarg_t);
     56static void test_window_changed(void *, sysarg_t);
    5657
    5758static wndmgt_ops_t test_wndmgt_srv_ops = {
     
    6566static wndmgt_cb_t test_wndmgt_cb = {
    6667        .window_added = test_window_added,
    67         .window_removed = test_window_removed
     68        .window_removed = test_window_removed,
     69        .window_changed = test_window_changed
    6870};
    6971
     
    98100        bool window_removed_called;
    99101        sysarg_t window_removed_wnd_id;
     102
     103        bool window_changed_called;
     104        sysarg_t window_changed_wnd_id;
    100105
    101106        fibril_condvar_t event_cv;
     
    529534}
    530535
     536/** Window changed event can be delivered from server to client callback function */
     537PCUT_TEST(window_changed_deliver)
     538{
     539        errno_t rc;
     540        service_id_t sid;
     541        wndmgt_t *wndmgt = NULL;
     542        test_response_t resp;
     543
     544        async_set_fallback_port_handler(test_wndmgt_conn, &resp);
     545
     546        // FIXME This causes this test to be non-reentrant!
     547        rc = loc_server_register(test_wndmgt_server);
     548        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     549
     550        rc = loc_service_register(test_wndmgt_svc, &sid);
     551        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     552
     553        rc = wndmgt_open(test_wndmgt_svc, &test_wndmgt_cb, &resp, &wndmgt);
     554        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     555        PCUT_ASSERT_NOT_NULL(wndmgt);
     556        PCUT_ASSERT_NOT_NULL(resp.srv);
     557
     558        resp.event_cnt = 1;
     559        resp.event.etype = wmev_window_changed;
     560        resp.event.wnd_id = 42;
     561        resp.window_changed_called = false;
     562        fibril_mutex_initialize(&resp.event_lock);
     563        fibril_condvar_initialize(&resp.event_cv);
     564        wndmgt_srv_ev_pending(resp.srv);
     565
     566        /* Wait for the event handler to be called. */
     567        fibril_mutex_lock(&resp.event_lock);
     568        while (!resp.window_changed_called) {
     569                fibril_condvar_wait(&resp.event_cv, &resp.event_lock);
     570        }
     571        fibril_mutex_unlock(&resp.event_lock);
     572
     573        /* Verify that the event was delivered correctly */
     574        PCUT_ASSERT_INT_EQUALS(resp.event.etype,
     575            resp.revent.etype);
     576
     577        wndmgt_close(wndmgt);
     578
     579        rc = loc_service_unregister(sid);
     580        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     581}
     582
    531583/** Test window management service connection. */
    532584static void test_wndmgt_conn(ipc_call_t *icall, void *arg)
     
    569621        resp->window_removed_called = true;
    570622        resp->window_removed_wnd_id = wnd_id;
     623        fibril_condvar_broadcast(&resp->event_cv);
     624        fibril_mutex_unlock(&resp->event_lock);
     625}
     626
     627static void test_window_changed(void *arg, sysarg_t wnd_id)
     628{
     629        test_response_t *resp = (test_response_t *) arg;
     630
     631        resp->revent.etype = wmev_window_changed;
     632
     633        fibril_mutex_lock(&resp->event_lock);
     634        resp->window_changed_called = true;
     635        resp->window_changed_wnd_id = wnd_id;
    571636        fibril_condvar_broadcast(&resp->event_cv);
    572637        fibril_mutex_unlock(&resp->event_lock);
  • uspace/srv/hid/display/test/wmclient.c

    rfc00f0d rf1f433d  
    107107}
    108108
     109/** Test ds_wmclient_get_event(), ds_wmclient_post_wnd_removed_event(). */
     110PCUT_TEST(client_get_post_wnd_removed_event)
     111{
     112        ds_display_t *disp;
     113        ds_wmclient_t *wmclient;
     114        wndmgt_ev_t revent;
     115        bool called_cb = NULL;
     116        sysarg_t wnd_id;
     117        errno_t rc;
     118
     119        rc = ds_display_create(NULL, df_none, &disp);
     120        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     121
     122        rc = ds_wmclient_create(disp, &test_ds_wmclient_cb, &called_cb,
     123            &wmclient);
     124        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     125
     126        called_cb = false;
     127        wnd_id = 42;
     128
     129        rc = ds_wmclient_get_event(wmclient, &revent);
     130        PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
     131
     132        rc = ds_wmclient_post_wnd_removed_event(wmclient, wnd_id);
     133        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     134        PCUT_ASSERT_TRUE(called_cb);
     135
     136        rc = ds_wmclient_get_event(wmclient, &revent);
     137        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     138        PCUT_ASSERT_EQUALS(wnd_id, revent.wnd_id);
     139        PCUT_ASSERT_EQUALS(wmev_window_removed, revent.etype);
     140
     141        rc = ds_wmclient_get_event(wmclient, &revent);
     142        PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
     143
     144        ds_wmclient_destroy(wmclient);
     145        ds_display_destroy(disp);
     146}
     147
     148/** Test ds_wmclient_get_event(), ds_wmclient_post_wnd_changed_event(). */
     149PCUT_TEST(client_get_post_wnd_changed_event)
     150{
     151        ds_display_t *disp;
     152        ds_wmclient_t *wmclient;
     153        wndmgt_ev_t revent;
     154        bool called_cb = NULL;
     155        sysarg_t wnd_id;
     156        errno_t rc;
     157
     158        rc = ds_display_create(NULL, df_none, &disp);
     159        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     160
     161        rc = ds_wmclient_create(disp, &test_ds_wmclient_cb, &called_cb,
     162            &wmclient);
     163        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     164
     165        called_cb = false;
     166        wnd_id = 42;
     167
     168        rc = ds_wmclient_get_event(wmclient, &revent);
     169        PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
     170
     171        rc = ds_wmclient_post_wnd_changed_event(wmclient, wnd_id);
     172        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     173        PCUT_ASSERT_TRUE(called_cb);
     174
     175        rc = ds_wmclient_get_event(wmclient, &revent);
     176        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     177        PCUT_ASSERT_EQUALS(wnd_id, revent.wnd_id);
     178        PCUT_ASSERT_EQUALS(wmev_window_changed, revent.etype);
     179
     180        rc = ds_wmclient_get_event(wmclient, &revent);
     181        PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
     182
     183        ds_wmclient_destroy(wmclient);
     184        ds_display_destroy(disp);
     185}
     186
    109187/** Test ds_wmclient_purge_events() */
    110188PCUT_TEST(purge_events)
  • uspace/srv/hid/display/window.c

    rfc00f0d rf1f433d  
    4545#include <stdlib.h>
    4646#include <str.h>
     47#include <wndmgt.h>
    4748#include "client.h"
    4849#include "display.h"
    4950#include "seat.h"
    5051#include "window.h"
     52#include "wmclient.h"
    5153
    5254static void ds_window_invalidate_cb(void *, gfx_rect_t *);
     
    933935{
    934936        char *dcaption;
     937        ds_wmclient_t *wmclient;
    935938
    936939        dcaption = str_dup(caption);
     
    940943        free(wnd->caption);
    941944        wnd->caption = dcaption;
     945
     946        /* Notify window managers about window information change */
     947        wmclient = ds_display_first_wmclient(wnd->display);
     948        while (wmclient != NULL) {
     949                ds_wmclient_post_wnd_changed_event(wmclient, wnd->id);
     950                wmclient = ds_display_next_wmclient(wmclient);
     951        }
    942952
    943953        return EOK;
  • uspace/srv/hid/display/wmclient.c

    rfc00f0d rf1f433d  
    184184}
    185185
     186/** Post window changed event to the WM client's message queue.
     187 *
     188 * @param wmclient WM client
     189 * @param wnd_id Window ID of the added window
     190 *
     191 * @return EOK on success or an error code
     192 */
     193errno_t ds_wmclient_post_wnd_changed_event(ds_wmclient_t *wmclient,
     194    sysarg_t wnd_id)
     195{
     196        ds_wmclient_ev_t *wevent;
     197
     198        wevent = calloc(1, sizeof(ds_wmclient_ev_t));
     199        if (wevent == NULL)
     200                return ENOMEM;
     201
     202        wevent->wmclient = wmclient;
     203        wevent->event.etype = wmev_window_changed;
     204        wevent->event.wnd_id = wnd_id;
     205        list_append(&wevent->levents, &wmclient->events);
     206
     207        /* Notify the client */
     208        // TODO Do not send more than once until client drains the queue
     209        if (wmclient->cb != NULL && wmclient->cb->ev_pending != NULL)
     210                wmclient->cb->ev_pending(wmclient->cb_arg);
     211
     212        return EOK;
     213}
     214
    186215/** @}
    187216 */
  • uspace/srv/hid/display/wmclient.h

    rfc00f0d rf1f433d  
    4848extern errno_t ds_wmclient_post_wnd_added_event(ds_wmclient_t *, sysarg_t);
    4949extern errno_t ds_wmclient_post_wnd_removed_event(ds_wmclient_t *, sysarg_t);
     50extern errno_t ds_wmclient_post_wnd_changed_event(ds_wmclient_t *, sysarg_t);
    5051extern void ds_wmclient_purge_events(ds_wmclient_t *);
    5152
Note: See TracChangeset for help on using the changeset viewer.