Changeset 66be0288 in mainline for uspace


Ignore:
Timestamp:
2014-01-17T17:02:59Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
476f62c, facc34d
Parents:
2e80321 (diff), 61b5b73d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Mainline changes

Location:
uspace
Files:
6 added
1 deleted
29 edited
2 moved

Legend:

Unmodified
Added
Removed
  • uspace/Makefile

    r2e80321 r66be0288  
    5050        app/kill \
    5151        app/killall \
    52         app/klog \
     52        app/kio \
    5353        app/loc \
    5454        app/logset \
     
    9292        srv/locsrv \
    9393        srv/logger \
     94        srv/klog \
    9495        srv/devman \
    9596        srv/loader \
  • uspace/app/init/init.c

    r2e80321 r66be0288  
    336336                srv_start("/srv/tmpfs");
    337337       
     338        srv_start("/srv/klog");
    338339        srv_start("/srv/locfs");
    339340        srv_start("/srv/taskmon");
  • uspace/app/kio/Makefile

    r2e80321 r66be0288  
    3131LIBS = $(LIBCLUI_PREFIX)/libclui.a
    3232EXTRA_CFLAGS = -I$(LIBCLUI_PREFIX)
    33 BINARY = klog
     33BINARY = kio
    3434
    3535SOURCES = \
    36         klog.c
     36        kio.c
    3737
    3838include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/kio/kio.c

    r2e80321 r66be0288  
    2727 */
    2828
    29 /** @addtogroup klog KLog
    30  * @brief HelenOS KLog
     29/** @addtogroup kio KIO
     30 * @brief HelenOS KIO
    3131 * @{
    3232 */
     
    4242#include <errno.h>
    4343#include <str_error.h>
    44 #include <io/klog.h>
     44#include <io/kio.h>
    4545#include <sysinfo.h>
    4646#include <malloc.h>
     
    5050#include <tinput.h>
    5151
    52 #define NAME       "klog"
    53 #define LOG_FNAME  "/log/klog"
     52#define NAME       "kio"
     53#define LOG_FNAME  "/log/kio"
    5454
    5555/* Producer/consumer buffers */
     
    6262static prodcons_t pc;
    6363
    64 /* Pointer to klog area */
    65 static wchar_t *klog;
    66 static size_t klog_length;
     64/* Pointer to kio area */
     65static wchar_t *kio;
     66static size_t kio_length;
    6767
    6868/* Notification mutex */
     
    7575 *
    7676 * @param length Number of characters to copy.
    77  * @param data   Pointer to the kernel klog buffer.
     77 * @param data   Pointer to the kernel kio buffer.
    7878 *
    7979 */
     
    142142/** Kernel notification handler
    143143 *
    144  * Receives kernel klog notifications.
     144 * Receives kernel kio notifications.
    145145 *
    146146 * @param callid IPC call ID
     
    156156         * starving.
    157157         *
    158          * Note: Usually the automatic masking of the klog
     158         * Note: Usually the automatic masking of the kio
    159159         * notifications on the kernel side does the trick
    160160         * of limiting the chance of accidentally copying
    161161         * the same data multiple times. However, due to
    162          * the non-blocking architecture of klog notifications,
     162         * the non-blocking architecture of kio notifications,
    163163         * this possibility cannot be generally avoided.
    164164         */
     
    166166        fibril_mutex_lock(&mtx);
    167167       
    168         size_t klog_start = (size_t) IPC_GET_ARG1(*call);
    169         size_t klog_len = (size_t) IPC_GET_ARG2(*call);
    170         size_t klog_stored = (size_t) IPC_GET_ARG3(*call);
    171        
    172         size_t offset = (klog_start + klog_len - klog_stored) % klog_length;
     168        size_t kio_start = (size_t) IPC_GET_ARG1(*call);
     169        size_t kio_len = (size_t) IPC_GET_ARG2(*call);
     170        size_t kio_stored = (size_t) IPC_GET_ARG3(*call);
     171       
     172        size_t offset = (kio_start + kio_len - kio_stored) % kio_length;
    173173       
    174174        /* Copy data from the ring buffer */
    175         if (offset + klog_stored >= klog_length) {
    176                 size_t split = klog_length - offset;
    177                
    178                 producer(split, klog + offset);
    179                 producer(klog_stored - split, klog);
     175        if (offset + kio_stored >= kio_length) {
     176                size_t split = kio_length - offset;
     177               
     178                producer(split, kio + offset);
     179                producer(kio_stored - split, kio);
    180180        } else
    181                 producer(klog_stored, klog + offset);
    182        
    183         event_unmask(EVENT_KLOG);
     181                producer(kio_stored, kio + offset);
     182       
     183        event_unmask(EVENT_KIO);
    184184        fibril_mutex_unlock(&mtx);
    185185}
     
    188188{
    189189        size_t pages;
    190         int rc = sysinfo_get_value("klog.pages", &pages);
    191         if (rc != EOK) {
    192                 fprintf(stderr, "%s: Unable to get number of klog pages\n",
     190        int rc = sysinfo_get_value("kio.pages", &pages);
     191        if (rc != EOK) {
     192                fprintf(stderr, "%s: Unable to get number of kio pages\n",
    193193                    NAME);
    194194                return rc;
     
    196196       
    197197        uintptr_t faddr;
    198         rc = sysinfo_get_value("klog.faddr", &faddr);
    199         if (rc != EOK) {
    200                 fprintf(stderr, "%s: Unable to get klog physical address\n",
     198        rc = sysinfo_get_value("kio.faddr", &faddr);
     199        if (rc != EOK) {
     200                fprintf(stderr, "%s: Unable to get kio physical address\n",
    201201                    NAME);
    202202                return rc;
     
    204204       
    205205        size_t size = pages * PAGE_SIZE;
    206         klog_length = size / sizeof(wchar_t);
     206        kio_length = size / sizeof(wchar_t);
    207207       
    208208        rc = physmem_map(faddr, pages, AS_AREA_READ | AS_AREA_CACHEABLE,
    209             (void *) &klog);
    210         if (rc != EOK) {
    211                 fprintf(stderr, "%s: Unable to map klog\n", NAME);
     209            (void *) &kio);
     210        if (rc != EOK) {
     211                fprintf(stderr, "%s: Unable to map kio\n", NAME);
    212212                return rc;
    213213        }
     
    215215        prodcons_initialize(&pc);
    216216        async_set_interrupt_received(notification_received);
    217         rc = event_subscribe(EVENT_KLOG, 0);
    218         if (rc != EOK) {
    219                 fprintf(stderr, "%s: Unable to register klog notifications\n",
     217        rc = event_subscribe(EVENT_KIO, 0);
     218        if (rc != EOK) {
     219                fprintf(stderr, "%s: Unable to register kio notifications\n",
    220220                    NAME);
    221221                return rc;
     
    236236
    237237        fibril_add_ready(fid);
    238         event_unmask(EVENT_KLOG);
    239         klog_update();
    240        
    241         tinput_set_prompt(input, "klog> ");
     238        event_unmask(EVENT_KIO);
     239        kio_update();
     240       
     241        tinput_set_prompt(input, "kio> ");
    242242
    243243        char *str;
     
    248248                }
    249249
    250                 klog_command(str, str_size(str));
     250                kio_command(str, str_size(str));
    251251                free(str);
    252252        }
  • uspace/app/trace/syscalls.c

    r2e80321 r66be0288  
    3838
    3939const sc_desc_t syscall_desc[] = {
    40     [SYS_KLOG] ={ "klog",                               3,      V_INT_ERRNO },
     40    [SYS_KIO] ={ "kio",                                 3,      V_INT_ERRNO },
    4141    [SYS_TLS_SET] = { "tls_set",                        1,      V_ERRNO },
    4242
  • uspace/app/vdemo/vdemo.c

    r2e80321 r66be0288  
    110110{
    111111        if (argc >= 2) {
    112                 window_t *main_window = window_open(argv[1], true, true, "vdemo", 0, 0);
     112                window_t *main_window = window_open(argv[1], true, true, "vdemo");
    113113                if (!main_window) {
    114114                        printf("Cannot open main window.\n");
     
    117117
    118118                pixel_t grd_bg = PIXEL(255, 240, 240, 240);
    119                 pixel_t btn_bg = PIXEL(255, 0, 0, 0);
    120                 pixel_t btn_fg = PIXEL(255, 240, 240, 240);
     119               
     120                pixel_t btn_bg = PIXEL(255, 240, 240, 240);
     121                pixel_t btn_fg = PIXEL(255, 186, 186, 186);
     122                pixel_t btn_text = PIXEL(255, 0, 0, 0);
     123               
    121124                pixel_t lbl_bg = PIXEL(255, 240, 240, 240);
    122                 pixel_t lbl_fg = PIXEL(255, 0, 0, 0);
     125                pixel_t lbl_text = PIXEL(255, 0, 0, 0);
    123126
    124                 my_label_t *lbl_action = create_my_label(NULL, "Hello there!", 16, lbl_bg, lbl_fg);
    125                 button_t *btn_confirm = create_button(NULL, "Confirm", 16, btn_bg, btn_fg);
    126                 button_t *btn_cancel = create_button(NULL, "Cancel", 16, btn_bg, btn_fg);
     127                my_label_t *lbl_action = create_my_label(NULL, "Hello there!", 16,
     128                    lbl_bg, lbl_text);
     129                button_t *btn_confirm = create_button(NULL, "Confirm", 16, btn_bg,
     130                    btn_fg, btn_text);
     131                button_t *btn_cancel = create_button(NULL, "Cancel", 16, btn_bg,
     132                    btn_fg, btn_text);
    127133                grid_t *grid = create_grid(window_root(main_window), 2, 2, grd_bg);
    128134                if (!lbl_action || !btn_confirm || !btn_cancel || !grid) {
     
    144150                grid->add(grid, &btn_confirm->widget, 0, 1, 1, 1);
    145151                grid->add(grid, &btn_cancel->widget, 1, 1, 1, 1);
    146                 window_resize(main_window, 200, 76);
     152                window_resize(main_window, 0, 0, 200, 76,
     153                    WINDOW_PLACEMENT_CENTER);
    147154
    148155                window_exec(main_window);
  • uspace/app/viewer/viewer.c

    r2e80321 r66be0288  
    166166        }
    167167       
    168         main_window = window_open(argv[1], true, false, "viewer", 0, 0);
     168        main_window = window_open(argv[1], true, false, "viewer");
    169169        if (!main_window) {
    170170                printf("Cannot open main window.\n");
     
    192192        }
    193193       
    194         window_resize(main_window, WINDOW_WIDTH, WINDOW_HEIGHT);
     194        window_resize(main_window, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT,
     195            WINDOW_PLACEMENT_ABSOLUTE);
    195196        window_exec(main_window);
    196197       
  • uspace/app/vlaunch/vlaunch.c

    r2e80321 r66be0288  
    115115       
    116116        winreg = argv[1];
    117         window_t *main_window = window_open(argv[1], true, true, "vlaunch", 0, 0);
     117        window_t *main_window = window_open(argv[1], true, true, "vlaunch");
    118118        if (!main_window) {
    119119                printf("Cannot open main window.\n");
     
    122122       
    123123        pixel_t grd_bg = PIXEL(255, 255, 255, 255);
    124         pixel_t btn_bg = PIXEL(255, 0, 0, 0);
    125         pixel_t btn_fg = PIXEL(255, 240, 240, 240);
     124       
     125        pixel_t btn_bg = PIXEL(255, 255, 255, 255);
     126        pixel_t btn_fg = PIXEL(255, 186, 186, 186);
     127        pixel_t btn_text = PIXEL(255, 0, 0, 0);
     128       
    126129        pixel_t lbl_bg = PIXEL(255, 255, 255, 255);
    127         pixel_t lbl_fg = PIXEL(255, 0, 0, 0);
     130        pixel_t lbl_text = PIXEL(255, 0, 0, 0);
    128131       
    129132        canvas_t *logo_canvas = create_canvas(NULL, LOGO_WIDTH, LOGO_HEIGHT,
    130133            logo);
    131134        label_t *lbl_caption = create_label(NULL, "Launch application:", 16,
    132             lbl_bg, lbl_fg);
     135            lbl_bg, lbl_text);
    133136        button_t *btn_vterm = create_button(NULL, "vterm", 16, btn_bg,
    134             btn_fg);
     137            btn_fg, btn_text);
    135138        button_t *btn_vdemo = create_button(NULL, "vdemo", 16, btn_bg,
    136             btn_fg);
     139            btn_fg, btn_text);
    137140        button_t *btn_vlaunch = create_button(NULL, "vlaunch", 16, btn_bg,
    138             btn_fg);
     141            btn_fg, btn_text);
    139142        grid_t *grid = create_grid(window_root(main_window), 1, 5, grd_bg);
    140143       
     
    156159        grid->add(grid, &btn_vlaunch->widget, 0, 4, 1, 1);
    157160       
    158         window_resize(main_window, 210, 130 + LOGO_HEIGHT);
     161        window_resize(main_window, 0, 0, 210, 130 + LOGO_HEIGHT,
     162            WINDOW_PLACEMENT_RIGHT | WINDOW_PLACEMENT_TOP);
    159163        window_exec(main_window);
    160164       
  • uspace/app/vterm/vterm.c

    r2e80321 r66be0288  
    4949        }
    5050       
    51         window_t *main_window = window_open(argv[1], true, true, "vterm", 0, 0);
     51        window_t *main_window = window_open(argv[1], true, true, "vterm");
    5252        if (!main_window) {
    5353                printf("%s: Cannot open main window.\n", NAME);
     
    5555        }
    5656       
    57         window_resize(main_window, 650, 510);
     57        window_resize(main_window, 0, 0, 648, 508, WINDOW_PLACEMENT_ANY);
    5858        terminal_t *terminal_widget =
    5959            create_terminal(window_root(main_window), 640, 480);
  • uspace/lib/c/Makefile

    r2e80321 r66be0288  
    101101        generic/io/log.c \
    102102        generic/io/logctl.c \
     103        generic/io/kio.c \
    103104        generic/io/klog.c \
    104105        generic/io/snprintf.c \
  • uspace/lib/c/generic/assert.c

    r2e80321 r66be0288  
    3333#include <assert.h>
    3434#include <stdio.h>
    35 #include <io/klog.h>
     35#include <io/kio.h>
    3636#include <stdlib.h>
    3737#include <atomic.h>
     
    4444{
    4545        /*
    46          * Send the message safely to klog. Nested asserts should not occur.
     46         * Send the message safely to kio. Nested asserts should not occur.
    4747         */
    48         klog_printf("Assertion failed (%s) in file \"%s\", line %u.\n",
     48        kio_printf("Assertion failed (%s) in file \"%s\", line %u.\n",
    4949            cond, file, line);
    5050       
  • uspace/lib/c/generic/io/io.c

    r2e80321 r66be0288  
    4242#include <malloc.h>
    4343#include <async.h>
    44 #include <io/klog.h>
     44#include <io/kio.h>
    4545#include <vfs/vfs.h>
    4646#include <vfs/vfs_sess.h>
     
    5757        .error = true,
    5858        .eof = true,
    59         .klog = false,
     59        .kio = false,
    6060        .sess = NULL,
    6161        .btype = _IONBF,
     
    6767};
    6868
    69 static FILE stdout_klog = {
     69static FILE stdout_kio = {
    7070        .fd = -1,
    7171        .error = false,
    7272        .eof = false,
    73         .klog = true,
     73        .kio = true,
    7474        .sess = NULL,
    7575        .btype = _IOLBF,
     
    8181};
    8282
    83 static FILE stderr_klog = {
     83static FILE stderr_kio = {
    8484        .fd = -1,
    8585        .error = false,
    8686        .eof = false,
    87         .klog = true,
     87        .kio = true,
    8888        .sess = NULL,
    8989        .btype = _IONBF,
     
    113113                stdout = fdopen(1, "w");
    114114        } else {
    115                 stdout = &stdout_klog;
     115                stdout = &stdout_kio;
    116116                list_append(&stdout->link, &files);
    117117        }
     
    120120                stderr = fdopen(2, "w");
    121121        } else {
    122                 stderr = &stderr_klog;
     122                stderr = &stderr_kio;
    123123                list_append(&stderr->link, &files);
    124124        }
     
    267267        stream->error = false;
    268268        stream->eof = false;
    269         stream->klog = false;
     269        stream->kio = false;
    270270        stream->sess = NULL;
    271271        stream->need_sync = false;
     
    289289        stream->error = false;
    290290        stream->eof = false;
    291         stream->klog = false;
     291        stream->kio = false;
    292292        stream->sess = NULL;
    293293        stream->need_sync = false;
     
    314314       
    315315        if ((stream != &stdin_null)
    316             && (stream != &stdout_klog)
    317             && (stream != &stderr_klog))
     316            && (stream != &stdout_kio)
     317            && (stream != &stderr_kio))
    318318                free(stream);
    319319       
     
    382382                ssize_t wr;
    383383               
    384                 if (stream->klog)
    385                         wr = klog_write(buf + done, left);
     384                if (stream->kio)
     385                        wr = kio_write(buf + done, left);
    386386                else
    387387                        wr = write(stream->fd, buf + done, left);
     
    705705        _fflushbuf(stream);
    706706       
    707         if (stream->klog) {
    708                 klog_update();
     707        if (stream->kio) {
     708                kio_update();
    709709                return EOK;
    710710        }
     
    740740int fileno(FILE *stream)
    741741{
    742         if (stream->klog) {
     742        if (stream->kio) {
    743743                errno = EBADF;
    744744                return -1;
  • uspace/lib/c/generic/io/klog.c

    r2e80321 r66be0288  
    11/*
    2  * Copyright (c) 2006 Josef Cejka
    3  * Copyright (c) 2006 Jakub Vana
     2 * Copyright (c) 2013 Martin Sucha
    43 * All rights reserved.
    54 *
     
    4140#include <abi/klog.h>
    4241#include <io/klog.h>
    43 #include <io/printf_core.h>
     42#include <abi/log.h>
    4443
    45 size_t klog_write(const void *buf, size_t size)
     44size_t klog_write(log_level_t lvl, const void *buf, size_t size)
    4645{
    47         ssize_t ret = (ssize_t) __SYSCALL3(SYS_KLOG, KLOG_WRITE, (sysarg_t) buf, size);
     46        ssize_t ret = (ssize_t) __SYSCALL4(SYS_KLOG, KLOG_WRITE, (sysarg_t) buf,
     47            size, lvl);
    4848       
    4949        if (ret >= 0)
     
    5353}
    5454
    55 void klog_update(void)
     55int klog_read(void *data, size_t size)
    5656{
    57         (void) __SYSCALL3(SYS_KLOG, KLOG_UPDATE, (uintptr_t) NULL, 0);
    58 }
    59 
    60 void klog_command(const void *buf, size_t size)
    61 {
    62         (void) __SYSCALL3(SYS_KLOG, KLOG_COMMAND, (sysarg_t) buf, (sysarg_t) size);
    63 }
    64 
    65 /** Print formatted text to klog.
    66  *
    67  * @param fmt Format string
    68  *
    69  * \see For more details about format string see printf_core.
    70  *
    71  */
    72 int klog_printf(const char *fmt, ...)
    73 {
    74         va_list args;
    75         va_start(args, fmt);
    76        
    77         int ret = klog_vprintf(fmt, args);
    78        
    79         va_end(args);
    80        
    81         return ret;
    82 }
    83 
    84 static int klog_vprintf_str_write(const char *str, size_t size, void *data)
    85 {
    86         size_t wr = klog_write(str, size);
    87         return str_nlength(str, wr);
    88 }
    89 
    90 static int klog_vprintf_wstr_write(const wchar_t *str, size_t size, void *data)
    91 {
    92         size_t offset = 0;
    93         size_t chars = 0;
    94        
    95         while (offset < size) {
    96                 char buf[STR_BOUNDS(1)];
    97                 size_t sz = 0;
    98                
    99                 if (chr_encode(str[chars], buf, &sz, STR_BOUNDS(1)) == EOK)
    100                         klog_write(buf, sz);
    101                
    102                 chars++;
    103                 offset += sizeof(wchar_t);
    104         }
    105        
    106         return chars;
    107 }
    108 
    109 /** Print formatted text to klog.
    110  *
    111  * @param fmt Format string
    112  * @param ap  Format parameters
    113  *
    114  * \see For more details about format string see printf_core.
    115  *
    116  */
    117 int klog_vprintf(const char *fmt, va_list ap)
    118 {
    119         printf_spec_t ps = {
    120                 klog_vprintf_str_write,
    121                 klog_vprintf_wstr_write,
    122                 NULL
    123         };
    124        
    125         return printf_core(fmt, &ps, ap);
     57        return (int) __SYSCALL4(SYS_KLOG, KLOG_READ, (uintptr_t) data, size, 0);
    12658}
    12759
  • uspace/lib/c/generic/io/window.c

    r2e80321 r66be0288  
    4040#include <stdio.h>
    4141
    42 int win_register(async_sess_t *sess, service_id_t *in, service_id_t *out,
    43     sysarg_t x_offset, sysarg_t y_offset)
     42int win_register(async_sess_t *sess, service_id_t *in, service_id_t *out)
    4443{
    4544        async_exch_t *exch = async_exchange_begin(sess);
    46         int ret = async_req_2_2(exch, WINDOW_REGISTER, x_offset, y_offset, in, out);
     45        int ret = async_req_0_2(exch, WINDOW_REGISTER, in, out);
    4746        async_exchange_end(exch);
    48 
     47       
    4948        return ret;
    5049}
     
    9291}
    9392
    94 int win_resize(async_sess_t *sess, sysarg_t width, sysarg_t height, void *cells)
     93int win_resize(async_sess_t *sess, sysarg_t x, sysarg_t y, sysarg_t width,
     94    sysarg_t height, window_placement_flags_t placement_flags, void *cells)
    9595{
    9696        async_exch_t *exch = async_exchange_begin(sess);
    97 
     97       
    9898        ipc_call_t answer;
    99         aid_t req = async_send_2(exch, WINDOW_RESIZE, width, height, &answer);
    100 
     99        aid_t req = async_send_5(exch, WINDOW_RESIZE, x, y, width, height,
     100            (sysarg_t) placement_flags, &answer);
     101       
    101102        int rc = async_share_out_start(exch, cells, AS_AREA_READ | AS_AREA_CACHEABLE);
    102 
     103       
    103104        async_exchange_end(exch);
    104 
     105       
    105106        sysarg_t ret;
    106107        async_wait_for(req, &ret);
    107 
    108         if (rc != EOK) {
     108       
     109        if (rc != EOK)
    109110                return rc;
    110         } else if (ret != EOK) {
     111        else if (ret != EOK)
    111112                return ret;
    112         } else {
    113                 return EOK;
    114         }
     113       
     114        return EOK;
    115115}
    116116
  • uspace/lib/c/generic/private/stdio.h

    r2e80321 r66be0288  
    5353        int eof;
    5454       
    55         /** Klog indicator */
    56         int klog;
     55        /** KIO indicator */
     56        int kio;
    5757       
    5858        /** Session to the file provider */
  • uspace/lib/c/include/io/klog.h

    r2e80321 r66be0288  
    11/*
    2  * Copyright (c) 2006 Jakub Vana
     2 * Copyright (c) 2013 Martin Sucha
    33 * All rights reserved.
    44 *
     
    3939#include <stdarg.h>
    4040#include <io/verify.h>
     41#include <stdio.h>
     42#include <stdlib.h>
     43#include <str.h>
     44#include <abi/log.h>
    4145
    42 extern size_t klog_write(const void *, size_t);
    43 extern void klog_update(void);
    44 extern void klog_command(const void *, size_t);
    45 extern int klog_printf(const char *, ...)
    46     PRINTF_ATTRIBUTE(1, 2);
    47 extern int klog_vprintf(const char *, va_list);
     46extern size_t klog_write(log_level_t, const void *, size_t);
     47extern int klog_read(void *, size_t);
     48
     49#define KLOG_PRINTF(lvl, fmt, ...) ({ \
     50        char *_fmt = str_dup(fmt); \
     51        size_t _fmtsize = str_size(_fmt); \
     52        if (_fmtsize > 0 && _fmt[_fmtsize - 1] == '\n') \
     53                _fmt[_fmtsize - 1] = 0; \
     54        char *_s; \
     55        int _c = asprintf(&_s, _fmt, ##__VA_ARGS__); \
     56        free(_fmt); \
     57        if (_c >= 0) { \
     58                _c = klog_write((lvl), _s, str_size(_s)); \
     59                free(_s); \
     60        }; \
     61        (_c >= 0); \
     62})
    4863
    4964#endif
  • uspace/lib/c/include/io/log.h

    r2e80321 r66be0288  
    3939#include <io/verify.h>
    4040
    41 /** Log message level. */
    42 typedef enum {
    43         /** Fatal error, program is not able to recover at all. */
    44         LVL_FATAL,
    45         /** Serious error but the program can recover from it. */
    46         LVL_ERROR,
    47         /** Easily recoverable problem. */
    48         LVL_WARN,
    49         /** Information message that ought to be printed by default. */
    50         LVL_NOTE,
    51         /** Debugging purpose message. */
    52         LVL_DEBUG,
    53         /** More detailed debugging message. */
    54         LVL_DEBUG2,
    55        
    56         /** For checking range of values */
    57         LVL_LIMIT
    58 } log_level_t;
     41#include <abi/log.h>
    5942
    6043/** Log itself (logging target). */
  • uspace/lib/c/include/io/window.h

    r2e80321 r66be0288  
    4343#include <io/pos_event.h>
    4444
     45typedef enum {
     46        GF_EMPTY = 0,
     47        GF_MOVE_X = 1,
     48        GF_MOVE_Y = 2,
     49        GF_RESIZE_X = 4,
     50        GF_RESIZE_Y = 8,
     51        GF_SCALE_X = 16,
     52        GF_SCALE_Y = 32
     53} window_grab_flags_t;
     54
     55typedef enum {
     56        WINDOW_PLACEMENT_ANY = 0,
     57        WINDOW_PLACEMENT_CENTER_X = 1,
     58        WINDOW_PLACEMENT_CENTER_Y = 2,
     59        WINDOW_PLACEMENT_CENTER =
     60            WINDOW_PLACEMENT_CENTER_X | WINDOW_PLACEMENT_CENTER_Y,
     61        WINDOW_PLACEMENT_LEFT = 4,
     62        WINDOW_PLACEMENT_RIGHT = 8,
     63        WINDOW_PLACEMENT_TOP = 16,
     64        WINDOW_PLACEMENT_BOTTOM = 32,
     65        WINDOW_PLACEMENT_ABSOLUTE_X = 64,
     66        WINDOW_PLACEMENT_ABSOLUTE_Y = 128,
     67        WINDOW_PLACEMENT_ABSOLUTE =
     68            WINDOW_PLACEMENT_ABSOLUTE_X | WINDOW_PLACEMENT_ABSOLUTE_Y
     69} window_placement_flags_t;
     70
    4571typedef struct {
    4672        sysarg_t object;
    4773        sysarg_t slot;
    4874        sysarg_t argument;
    49 } sig_event_t;
     75} signal_event_t;
    5076
    5177typedef struct {
     78        sysarg_t offset_x;
     79        sysarg_t offset_y;
    5280        sysarg_t width;
    5381        sysarg_t height;
    54 } rsz_event_t;
     82        window_placement_flags_t placement_flags;
     83} resize_event_t;
    5584
    5685typedef enum {
     
    6998        kbd_event_t kbd;
    7099        pos_event_t pos;
    71         sig_event_t sig;
    72         rsz_event_t rsz;
     100        signal_event_t signal;
     101        resize_event_t resize;
    73102} window_event_data_t;
    74103
     
    79108} window_event_t;
    80109
    81 typedef enum {
    82         GF_EMPTY = 0,
    83         GF_MOVE_X = 1,
    84         GF_MOVE_Y = 2,
    85         GF_RESIZE_X = 4,
    86         GF_RESIZE_Y = 8,
    87         GF_SCALE_X = 16,
    88         GF_SCALE_Y = 32
    89 } window_grab_flags_t;
    90 
    91 extern int win_register(async_sess_t *, service_id_t *, service_id_t *, sysarg_t, sysarg_t);
     110extern int win_register(async_sess_t *, service_id_t *, service_id_t *);
    92111
    93112extern int win_get_event(async_sess_t *, window_event_t *);
     
    95114extern int win_damage(async_sess_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t);
    96115extern int win_grab(async_sess_t *, sysarg_t, sysarg_t);
    97 extern int win_resize(async_sess_t *, sysarg_t, sysarg_t, void *);
     116extern int win_resize(async_sess_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
     117    window_placement_flags_t, void *);
    98118extern int win_close(async_sess_t *);
    99119extern int win_close_request(async_sess_t *);
  • uspace/lib/c/include/stdio.h

    r2e80321 r66be0288  
    4040#include <str.h>
    4141#include <io/verify.h>
    42 #include <abi/klog.h>
     42#include <abi/kio.h>
    4343
    4444#define EOF  (-1)
     
    5252                int _n = snprintf(_buf, sizeof(_buf), fmt, ##__VA_ARGS__); \
    5353                if (_n > 0) \
    54                         (void) __SYSCALL3(SYS_KLOG, KLOG_WRITE, (sysarg_t) _buf, str_size(_buf)); \
     54                        (void) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) _buf, str_size(_buf)); \
    5555        }
    5656
  • uspace/lib/draw/cursor/embedded.c

    r2e80321 r66be0288  
    4646        assert(state_count);
    4747        assert(data);
    48 
     48       
    4949        (*state_count) = 1;
    5050        (*data) = NULL;
     
    5353static surface_t *cde_render(uint8_t state)
    5454{
    55         if (state != 0) {
     55        if (state != 0)
    5656                return NULL;
    57         }
    58 
     57       
    5958        surface_t *surface = surface_create(CURSOR_WIDTH, CURSOR_HEIGHT, NULL, 0);
    60 
    61         if (!surface) {
     59        if (!surface)
    6260                return NULL;
    63         }
    6461       
    6562        for (unsigned int y = 0; y < CURSOR_HEIGHT; ++y) {
     
    6966                        pixel_t pixel = (cursor_texture[offset] & (1 << (x % 8))) ?
    7067                            PIXEL(255, 0, 0, 0) : PIXEL(255, 255, 255, 255);
    71                         surface_put_pixel(surface, x, y, visible ? pixel : PIXEL(0, 0, 0, 0));
     68                       
     69                        if (visible)
     70                                surface_put_pixel(surface, x, y, pixel);
    7271                }
    7372        }
    74 
     73       
    7574        return surface;
    7675}
  • uspace/lib/gui/Makefile

    r2e80321 r66be0288  
    3434
    3535SOURCES = \
     36        common.c \
    3637        button.c \
    3738        canvas.c \
  • uspace/lib/gui/button.c

    r2e80321 r66be0288  
    3636#include <str.h>
    3737#include <malloc.h>
    38 
    3938#include <drawctx.h>
    4039#include <surface.h>
    41 
     40#include "common.h"
    4241#include "window.h"
    4342#include "button.h"
    4443
    45 static void paint_internal(widget_t *w)
    46 {
    47         button_t *btn = (button_t *) w;
    48 
     44static pixel_t color_highlight = PIXEL(255, 255, 255, 255);
     45static pixel_t color_shadow = PIXEL(255, 85, 85, 85);
     46
     47static void paint_internal(widget_t *widget)
     48{
     49        button_t *btn = (button_t *) widget;
     50       
    4951        surface_t *surface = window_claim(btn->widget.window);
    50         if (!surface) {
     52        if (!surface)
    5153                window_yield(btn->widget.window);
     54       
     55        source_t source;
     56        source_init(&source);
     57       
     58        drawctx_t drawctx;
     59        drawctx_init(&drawctx, surface);
     60       
     61        drawctx_set_source(&drawctx, &btn->background);
     62        drawctx_transfer(&drawctx, widget->hpos, widget->vpos,
     63            widget->width, widget->height);
     64       
     65        if ((widget->width >= 8) && (widget->height >= 8)) {
     66                drawctx_set_source(&drawctx, &source);
     67                draw_bevel(&drawctx, &source, widget->hpos + 3, widget->vpos + 3,
     68                    widget->width - 6, widget->height - 6, color_highlight,
     69                    color_shadow);
     70               
     71                drawctx_set_source(&drawctx, &btn->foreground);
     72                drawctx_transfer(&drawctx, widget->hpos + 4, widget->vpos + 4,
     73                    widget->width - 8, widget->height - 8);
    5274        }
    53 
    54         drawctx_t drawctx;
    55 
    56         drawctx_init(&drawctx, surface);
    57         drawctx_set_source(&drawctx, &btn->foreground);
    58         drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, w->height);
    59 
    60         if (w->width >= 6 && w->height >= 6) {
    61                 drawctx_set_source(&drawctx, &btn->background);
    62                 drawctx_transfer(&drawctx,
    63                     w->hpos + 3, w->vpos + 3, w->width - 6, w->height - 6);
    64         }
    65 
     75       
    6676        sysarg_t cpt_width;
    6777        sysarg_t cpt_height;
    6878        font_get_box(&btn->font, btn->caption, &cpt_width, &cpt_height);
    69         if (w->width >= cpt_width && w->height >= cpt_height) {
    70                 drawctx_set_source(&drawctx, &btn->foreground);
     79       
     80        if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) {
     81                sysarg_t x = ((widget->width - cpt_width) / 2) + widget->hpos;
     82                sysarg_t y = ((widget->height - cpt_height) / 2) + widget->vpos;
     83               
     84                drawctx_set_source(&drawctx, &btn->text);
    7185                drawctx_set_font(&drawctx, &btn->font);
    72                 sysarg_t x = ((w->width - cpt_width) / 2) + w->hpos;
    73                 sysarg_t y = ((w->height - cpt_height) / 2) + w->vpos;
    74                 if (btn->caption) {
     86               
     87                if (btn->caption)
    7588                        drawctx_print(&drawctx, btn->caption, x, y);
    76                 }
    7789        }
    78 
     90       
    7991        window_yield(btn->widget.window);
    8092}
     
    90102{
    91103        button_t *btn = (button_t *) widget;
    92 
     104       
    93105        deinit_button(btn);
    94        
    95106        free(btn);
    96107}
     
    117128{
    118129        button_t *btn = (button_t *) widget;
    119         if (event.key == KC_ENTER && event.type == KEY_PRESS) {
     130       
     131        if (event.key == KC_ENTER && event.type == KEY_PRESS)
    120132                sig_send(&btn->clicked, NULL);
    121         }
    122133}
    123134
     
    126137        button_t *btn = (button_t *) widget;
    127138        widget->window->focus = widget;
    128 
     139       
    129140        // TODO make the click logic more robust (mouse grabbing, mouse moves)
    130141        if (event.btn_num == 1) {
    131                 if (event.type == POS_RELEASE) {
     142                if (event.type == POS_RELEASE)
    132143                        sig_send(&btn->clicked, NULL);
    133                 }
    134144        }
    135145}
    136146
    137 bool init_button(button_t *btn, widget_t *parent,
    138     const char *caption, uint16_t points, pixel_t background, pixel_t foreground)
     147bool init_button(button_t *btn, widget_t *parent, const char *caption,
     148    uint16_t points, pixel_t background, pixel_t foreground, pixel_t text)
    139149{
    140150        widget_init(&btn->widget, parent);
    141 
     151       
    142152        btn->widget.destroy = button_destroy;
    143153        btn->widget.reconfigure = button_reconfigure;
     
    146156        btn->widget.handle_keyboard_event = button_handle_keyboard_event;
    147157        btn->widget.handle_position_event = button_handle_position_event;
    148 
     158       
    149159        source_init(&btn->background);
    150160        source_set_color(&btn->background, background);
     161       
    151162        source_init(&btn->foreground);
    152163        source_set_color(&btn->foreground, foreground);
    153 
    154         if (caption == NULL) {
     164       
     165        source_init(&btn->text);
     166        source_set_color(&btn->text, text);
     167       
     168        if (caption == NULL)
    155169                btn->caption = NULL;
    156         } else {
     170        else
    157171                btn->caption = str_dup(caption);
    158         }
     172       
    159173        font_init(&btn->font, FONT_DECODER_EMBEDDED, NULL, points);
    160 
     174       
    161175        sysarg_t cpt_width;
    162176        sysarg_t cpt_height;
    163177        font_get_box(&btn->font, btn->caption, &cpt_width, &cpt_height);
    164         btn->widget.width_min = cpt_width + 8;
    165         btn->widget.height_min = cpt_height + 8;
    166         btn->widget.width_ideal = cpt_width + 28;
    167         btn->widget.height_ideal = cpt_height + 8;
    168 
     178        btn->widget.width_min = cpt_width + 10;
     179        btn->widget.height_min = cpt_height + 10;
     180        btn->widget.width_ideal = cpt_width + 30;
     181        btn->widget.height_ideal = cpt_height + 10;
     182       
    169183        return true;
    170184}
    171185
    172 button_t *create_button(widget_t *parent,
    173     const char *caption, uint16_t points, pixel_t background, pixel_t foreground)
     186button_t *create_button(widget_t *parent, const char *caption, uint16_t points,
     187    pixel_t background, pixel_t foreground, pixel_t text)
    174188{
    175189        button_t *btn = (button_t *) malloc(sizeof(button_t));
    176         if (!btn) {
     190        if (!btn)
    177191                return NULL;
    178         }
    179 
    180         if (init_button(btn, parent, caption, points, background, foreground)) {
     192       
     193        if (init_button(btn, parent, caption, points, background, foreground,
     194            text))
    181195                return btn;
    182         } else {
    183                 free(btn);
    184                 return NULL;
    185         }
     196       
     197        free(btn);
     198        return NULL;
    186199}
    187200
  • uspace/lib/gui/button.h

    r2e80321 r66be0288  
    5050        source_t background;
    5151        source_t foreground;
     52        source_t text;
    5253        char *caption;
    5354        font_t font;
     
    5556} button_t;
    5657
    57 extern bool init_button(button_t *, widget_t *, const char *, uint16_t, pixel_t, pixel_t);
    58 extern button_t *create_button(widget_t *, const char *, uint16_t, pixel_t, pixel_t);
     58extern bool init_button(button_t *, widget_t *, const char *, uint16_t, pixel_t,
     59    pixel_t, pixel_t);
     60extern button_t *create_button(widget_t *, const char *, uint16_t, pixel_t,
     61    pixel_t, pixel_t);
    5962extern void deinit_button(button_t *);
    6063
  • uspace/lib/gui/connection.c

    r2e80321 r66be0288  
    210210                        link_initialize(&event->link);
    211211                        event->type = ET_SIGNAL_EVENT;
    212                         event->data.sig.object = (sysarg_t) cur->widget;
    213                         event->data.sig.slot = (sysarg_t) cur->slot;
    214                         event->data.sig.argument = (sysarg_t) data_copy;
     212                        event->data.signal.object = (sysarg_t) cur->widget;
     213                        event->data.signal.slot = (sysarg_t) cur->slot;
     214                        event->data.signal.argument = (sysarg_t) data_copy;
    215215                        prodcons_produce(&cur->widget->window->events, &event->link);
    216216                } else {
  • uspace/lib/gui/label.c

    r2e80321 r66be0288  
    3636#include <str.h>
    3737#include <malloc.h>
    38 
    3938#include <drawctx.h>
    4039#include <surface.h>
    41 
    4240#include "window.h"
    4341#include "label.h"
    4442
    45 static void paint_internal(widget_t *w)
     43static void paint_internal(widget_t *widget)
    4644{
    47         label_t *lbl = (label_t *) w;
     45        label_t *lbl = (label_t *) widget;
    4846
    4947        surface_t *surface = window_claim(lbl->widget.window);
    50         if (!surface) {
     48        if (!surface)
    5149                window_yield(lbl->widget.window);
    52         }
    53 
     50       
    5451        drawctx_t drawctx;
    55 
    5652        drawctx_init(&drawctx, surface);
     53       
    5754        drawctx_set_source(&drawctx, &lbl->background);
    58         drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, w->height);
    59 
     55        drawctx_transfer(&drawctx, widget->hpos, widget->vpos, widget->width,
     56            widget->height);
     57       
    6058        sysarg_t cpt_width;
    6159        sysarg_t cpt_height;
    6260        font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height);
    63         if (w->width >= cpt_width && w->height >= cpt_height) {
    64                 drawctx_set_source(&drawctx, &lbl->foreground);
     61       
     62        if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) {
     63                sysarg_t x = ((widget->width - cpt_width) / 2) + widget->hpos;
     64                sysarg_t y = ((widget->height - cpt_height) / 2) + widget->vpos;
     65               
     66                drawctx_set_source(&drawctx, &lbl->text);
    6567                drawctx_set_font(&drawctx, &lbl->font);
    66                 sysarg_t x = ((w->width - cpt_width) / 2) + w->hpos;
    67                 sysarg_t y = ((w->height - cpt_height) / 2) + w->vpos;
    68                 if (lbl->caption) {
     68               
     69                if (lbl->caption)
    6970                        drawctx_print(&drawctx, lbl->caption, x, y);
    70                 }
    7171        }
    72 
     72       
    7373        window_yield(lbl->widget.window);
    7474}
     
    7878        if (data != NULL) {
    7979                label_t *lbl = (label_t *) widget;
     80               
    8081                const char *new_caption = (const char *) data;
    8182                lbl->caption = str_dup(new_caption);
    82 
     83               
    8384                sysarg_t cpt_width;
    8485                sysarg_t cpt_height;
    8586                font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height);
     87               
    8688                lbl->widget.width_min = cpt_width + 4;
    8789                lbl->widget.height_min = cpt_height + 4;
    8890                lbl->widget.width_ideal = lbl->widget.width_min;
    8991                lbl->widget.height_ideal = lbl->widget.height_min;
    90 
     92               
    9193                window_refresh(lbl->widget.window);
    9294        }
     
    103105{
    104106        label_t *lbl = (label_t *) widget;
    105 
     107       
    106108        deinit_label(lbl);
    107        
    108109        free(lbl);
    109110}
     
    137138}
    138139
    139 bool init_label(label_t *lbl, widget_t *parent,
    140     const char *caption, uint16_t points, pixel_t background, pixel_t foreground)
     140bool init_label(label_t *lbl, widget_t *parent, const char *caption,
     141    uint16_t points, pixel_t background, pixel_t text)
    141142{
    142143        widget_init(&lbl->widget, parent);
    143 
     144       
    144145        lbl->widget.destroy = label_destroy;
    145146        lbl->widget.reconfigure = label_reconfigure;
     
    148149        lbl->widget.handle_keyboard_event = label_handle_keyboard_event;
    149150        lbl->widget.handle_position_event = label_handle_position_event;
    150 
     151       
    151152        source_init(&lbl->background);
    152153        source_set_color(&lbl->background, background);
    153         source_init(&lbl->foreground);
    154         source_set_color(&lbl->foreground, foreground);
    155 
    156         if (caption == NULL) {
     154       
     155        source_init(&lbl->text);
     156        source_set_color(&lbl->text, text);
     157       
     158        if (caption == NULL)
    157159                lbl->caption = NULL;
    158         } else {
     160        else
    159161                lbl->caption = str_dup(caption);
    160         }
     162       
    161163        font_init(&lbl->font, FONT_DECODER_EMBEDDED, NULL, points);
    162 
     164       
    163165        sysarg_t cpt_width;
    164166        sysarg_t cpt_height;
    165167        font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height);
     168       
    166169        lbl->widget.width_min = cpt_width + 4;
    167170        lbl->widget.height_min = cpt_height + 4;
    168171        lbl->widget.width_ideal = lbl->widget.width_min;
    169172        lbl->widget.height_ideal = lbl->widget.height_min;
    170 
     173       
    171174        lbl->rewrite = on_rewrite;
    172 
     175       
    173176        return true;
    174177}
    175178
    176 label_t *create_label(widget_t *parent,
    177     const char *caption, uint16_t points, pixel_t background, pixel_t foreground)
     179label_t *create_label(widget_t *parent, const char *caption, uint16_t points,
     180    pixel_t background, pixel_t text)
    178181{
    179182        label_t *lbl = (label_t *) malloc(sizeof(label_t));
    180         if (!lbl) {
     183        if (!lbl)
    181184                return NULL;
    182         }
    183 
    184         if (init_label(lbl, parent, caption, points, background, foreground)) {
     185       
     186        if (init_label(lbl, parent, caption, points, background, text))
    185187                return lbl;
    186         } else {
    187                 free(lbl);
    188                 return NULL;
    189         }
     188       
     189        free(lbl);
     190        return NULL;
    190191}
    191192
    192193/** @}
    193194 */
    194 
  • uspace/lib/gui/label.h

    r2e80321 r66be0288  
    4949        widget_t widget;
    5050        source_t background;
    51         source_t foreground;
     51        source_t text;
    5252        char *caption;
    5353        font_t font;
     
    5555} label_t;
    5656
    57 extern bool init_label(label_t *, widget_t *, const char *, uint16_t, pixel_t, pixel_t);
    58 extern label_t *create_label(widget_t *, const char *, uint16_t, pixel_t, pixel_t);
     57extern bool init_label(label_t *, widget_t *, const char *, uint16_t, pixel_t,
     58    pixel_t);
     59extern label_t *create_label(widget_t *, const char *, uint16_t, pixel_t,
     60    pixel_t);
    5961extern void deinit_label(label_t *);
    6062
  • uspace/lib/gui/window.c

    r2e80321 r66be0288  
    5656#include <surface.h>
    5757
     58#include "common.h"
    5859#include "connection.h"
    5960#include "widget.h"
    6061#include "window.h"
    6162
    62 static sysarg_t border_thickness = 5;
     63static sysarg_t border_thickness = 4;
     64static sysarg_t bevel_thickness = 1;
    6365static sysarg_t header_height = 20;
    6466static sysarg_t header_min_width = 40;
    65 static sysarg_t close_width = 20;
    66 
    67 static pixel_t border_color = PIXEL(255, 0, 0, 0);
    68 static pixel_t header_bg_focus_color = PIXEL(255, 88, 106, 196);
    69 static pixel_t header_fg_focus_color = PIXEL(255, 255, 255, 255);
    70 static pixel_t header_bg_unfocus_color = PIXEL(255, 12, 57, 92);
    71 static pixel_t header_fg_unfocus_color = PIXEL(255, 255, 255, 255);
    72 
    73 static void paint_internal(widget_t *w)
    74 {
    75         surface_t *surface = window_claim(w->window);
    76         if (!surface) {
    77                 window_yield(w->window);
    78         }
    79 
     67static sysarg_t close_thickness = 20;
     68
     69static pixel_t color_highlight = PIXEL(255, 255, 255, 255);
     70static pixel_t color_shadow = PIXEL(255, 85, 85, 85);
     71static pixel_t color_surface = PIXEL(255, 186, 186, 186);
     72
     73static pixel_t color_header_focus_highlight = PIXEL(255, 120, 145, 255);
     74static pixel_t color_header_focus_shadow = PIXEL(255, 40, 48, 89);
     75static pixel_t color_header_focus_surface = PIXEL(255, 88, 106, 196);
     76
     77static pixel_t color_header_unfocus_highlight = PIXEL(255, 16, 78, 126);
     78static pixel_t color_header_unfocus_shadow = PIXEL(255, 5, 26, 42);
     79static pixel_t color_header_unfocus_surface = PIXEL(255, 12, 57, 92);
     80
     81static pixel_t color_caption_focus = PIXEL(255, 255, 255, 255);
     82static pixel_t color_caption_unfocus = PIXEL(255, 207, 207, 207);
     83
     84static void paint_internal(widget_t *widget)
     85{
     86        surface_t *surface = window_claim(widget->window);
     87        if (!surface)
     88                window_yield(widget->window);
     89       
    8090        source_t source;
    81         font_t font;
     91        source_init(&source);
     92       
    8293        drawctx_t drawctx;
    83 
    84         source_init(&source);
    85         font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16);
    8694        drawctx_init(&drawctx, surface);
    8795        drawctx_set_source(&drawctx, &source);
     96       
     97        /* Window border outer bevel */
     98       
     99        draw_bevel(&drawctx, &source, widget->vpos, widget->hpos,
     100            widget->width, widget->height, color_highlight, color_shadow);
     101       
     102        /* Window border surface */
     103       
     104        source_set_color(&source, color_surface);
     105        drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1,
     106            widget->width - 2, 2);
     107        drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1,
     108            2, widget->height - 2);
     109        drawctx_transfer(&drawctx, widget->hpos + 1,
     110            widget->vpos + widget->height - 3, widget->width - 2, 2);
     111        drawctx_transfer(&drawctx, widget->hpos + widget->width - 3,
     112            widget->vpos + 1, 2, widget->height - 4);
     113       
     114        /* Window border inner bevel */
     115       
     116        draw_bevel(&drawctx, &source, widget->hpos + 3, widget->vpos + 3,
     117            widget->width - 6, widget->height - 6, color_shadow,
     118            color_highlight);
     119       
     120        /* Header bevel */
     121       
     122        sysarg_t header_hpos = widget->hpos + border_thickness;
     123        sysarg_t header_vpos = widget->vpos + border_thickness;
     124        sysarg_t header_width = widget->width - 2 * border_thickness -
     125            close_thickness;
     126       
     127        draw_bevel(&drawctx, &source, header_hpos, header_vpos,
     128            header_width, header_height, widget->window->is_focused ?
     129            color_header_focus_highlight : color_header_unfocus_highlight,
     130            widget->window->is_focused ?
     131            color_header_focus_shadow : color_header_unfocus_shadow);
     132       
     133        /* Header surface */
     134       
     135        source_set_color(&source, widget->window->is_focused ?
     136            color_header_focus_surface : color_header_unfocus_surface);
     137        drawctx_transfer(&drawctx, header_hpos + 1, header_vpos + 1,
     138            header_width - 2, header_height - 2);
     139       
     140        /* Close button bevel */
     141       
     142        sysarg_t close_hpos = widget->hpos + widget->width -
     143            border_thickness - close_thickness;
     144        sysarg_t close_vpos = widget->vpos + border_thickness;
     145       
     146        draw_bevel(&drawctx, &source, close_hpos, close_vpos,
     147            close_thickness, close_thickness, color_highlight, color_shadow);
     148       
     149        /* Close button surface */
     150       
     151        source_set_color(&source, color_surface);
     152        drawctx_transfer(&drawctx, close_hpos + 1, close_vpos + 1,
     153            close_thickness - 2, close_thickness - 2);
     154       
     155        /* Close button icon */
     156       
     157        draw_icon_cross(surface, close_hpos + 3, close_vpos + 3,
     158            color_highlight, color_shadow);
     159       
     160        /* Window caption */
     161       
     162        font_t font;
     163        font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16);
     164       
    88165        drawctx_set_font(&drawctx, &font);
    89 
    90         source_set_color(&source, border_color);
    91         drawctx_transfer(&drawctx, w->hpos, w->vpos, border_thickness, w->height);
    92         drawctx_transfer(&drawctx, w->hpos + w->width - border_thickness,
    93             w->vpos, border_thickness, w->height);
    94         drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, border_thickness);
    95         drawctx_transfer(&drawctx, w->hpos,
    96             w->vpos + w->height - border_thickness, w->width, border_thickness);
    97 
    98         source_set_color(&source,
    99             w->window->is_focused ? header_bg_focus_color : header_bg_unfocus_color);
    100         drawctx_transfer(&drawctx,
    101             w->hpos + border_thickness, w->vpos + border_thickness,
    102                 w->width - 2 * border_thickness, header_height);
    103 
     166        source_set_color(&source, widget->window->is_focused ?
     167            color_caption_focus : color_caption_unfocus);
     168       
    104169        sysarg_t cpt_width;
    105170        sysarg_t cpt_height;
    106         font_get_box(&font, w->window->caption, &cpt_width, &cpt_height);
    107         sysarg_t cls_width;
    108         sysarg_t cls_height;
    109         char cls_pict[] = "x";
    110         font_get_box(&font, cls_pict, &cls_width, &cls_height);
    111         source_set_color(&source,
    112             w->window->is_focused ? header_fg_focus_color : header_fg_unfocus_color);
    113         sysarg_t cls_x = ((close_width - cls_width) / 2) + w->hpos + w->width -
    114             border_thickness - close_width;
    115         sysarg_t cls_y = ((header_height - cls_height) / 2) + w->vpos + border_thickness;
    116         drawctx_print(&drawctx, cls_pict, cls_x, cls_y);
    117 
    118         bool draw_title = (w->width >= 2 * border_thickness + close_width + cpt_width);
     171        font_get_box(&font, widget->window->caption, &cpt_width, &cpt_height);
     172       
     173        bool draw_title =
     174            (widget->width >= 2 * border_thickness + 2 * bevel_thickness +
     175            close_thickness + cpt_width);
    119176        if (draw_title) {
    120                 sysarg_t cpt_x = ((w->width - cpt_width) / 2) + w->hpos;
    121                 sysarg_t cpt_y = ((header_height - cpt_height) / 2) + w->vpos + border_thickness;
    122                 if (w->window->caption) {
    123                         drawctx_print(&drawctx, w->window->caption, cpt_x, cpt_y);
    124                 }
    125         }
    126 
     177                sysarg_t cpt_x = ((widget->width - cpt_width) / 2) + widget->hpos;
     178                sysarg_t cpt_y = ((header_height - cpt_height) / 2) +
     179                    widget->vpos + border_thickness;
     180               
     181                if (widget->window->caption)
     182                        drawctx_print(&drawctx, widget->window->caption, cpt_x, cpt_y);
     183        }
     184       
    127185        font_release(&font);
    128         window_yield(w->window);
     186        window_yield(widget->window);
    129187}
    130188
     
    138196        if (widget->window->is_decorated) {
    139197                list_foreach(widget->children, link, widget_t, child) {
    140                         child->rearrange(child, 
     198                        child->rearrange(child,
    141199                            widget->hpos + border_thickness,
    142200                            widget->vpos + border_thickness + header_height,
     
    211269                    (event.vpos >= border_thickness) &&
    212270                    (event.vpos < border_thickness + header_height);
    213                 bool close = header && (event.hpos >= width - border_thickness - close_width);
     271                bool close = (header) &&
     272                    (event.hpos >= width - border_thickness - close_thickness);
    214273
    215274                if (top && left && allowed_button) {
     
    292351}
    293352
    294 static void handle_signal_event(window_t *win, sig_event_t event)
     353static void handle_signal_event(window_t *win, signal_event_t event)
    295354{
    296355        widget_t *widget = (widget_t *) event.object;
     
    303362}
    304363
    305 static void handle_resize(window_t *win, sysarg_t width, sysarg_t height)
    306 {
    307         int rc;
    308         surface_t *old_surface;
    309         surface_t *new_surface;
    310 
     364static void handle_resize(window_t *win, sysarg_t offset_x, sysarg_t offset_y,
     365    sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags)
     366{
    311367        if (width < 2 * border_thickness + header_min_width) {
    312368                win_damage(win->osess, 0, 0, 0, 0);
    313369                return;
    314370        }
    315 
     371       
    316372        if (height < 2 * border_thickness + header_height) {
    317373                win_damage(win->osess, 0, 0, 0, 0);
    318374                return;
    319375        }
    320 
     376       
    321377        /* Allocate resources for new surface. */
    322         new_surface = surface_create(width, height, NULL, SURFACE_FLAG_SHARED);
    323         if (!new_surface) {
     378        surface_t *new_surface = surface_create(width, height, NULL,
     379            SURFACE_FLAG_SHARED);
     380        if (!new_surface)
    324381                return;
    325         }
    326 
     382       
    327383        /* Switch new and old surface. */
    328384        fibril_mutex_lock(&win->guard);
    329         old_surface = win->surface;
     385        surface_t *old_surface = win->surface;
    330386        win->surface = new_surface;
    331387        fibril_mutex_unlock(&win->guard);
    332 
    333         /* Let all widgets in the tree alter their position and size. Widgets might
    334          * also paint themselves onto the new surface. */
     388       
     389        /*
     390         * Let all widgets in the tree alter their position and size.
     391         * Widgets might also paint themselves onto the new surface.
     392         */
    335393        win->root.rearrange(&win->root, 0, 0, width, height);
    336 
     394       
    337395        fibril_mutex_lock(&win->guard);
    338396        surface_reset_damaged_region(win->surface);
    339397        fibril_mutex_unlock(&win->guard);
    340 
     398       
    341399        /* Inform compositor about new surface. */
    342         rc = win_resize(win->osess,
    343                 width, height, surface_direct_access(new_surface));
    344 
     400        int rc = win_resize(win->osess, offset_x, offset_y, width, height,
     401            placement_flags, surface_direct_access(new_surface));
     402       
    345403        if (rc != EOK) {
    346404                /* Rollback to old surface. Reverse all changes. */
    347 
     405               
    348406                sysarg_t old_width = 0;
    349407                sysarg_t old_height = 0;
    350                 if (old_surface) {
     408                if (old_surface)
    351409                        surface_get_resolution(old_surface, &old_width, &old_height);
    352                 }
    353 
     410               
    354411                fibril_mutex_lock(&win->guard);
    355412                new_surface = win->surface;
    356413                win->surface = old_surface;
    357414                fibril_mutex_unlock(&win->guard);
    358 
     415               
    359416                win->root.rearrange(&win->root, 0, 0, old_width, old_height);
    360417               
     
    364421                        fibril_mutex_unlock(&win->guard);
    365422                }
    366 
     423               
    367424                surface_destroy(new_surface);
    368                 return;
    369         }
    370 
    371         /* Finally deallocate old surface. */
    372         if (old_surface) {
    373                 surface_destroy(old_surface);
     425        } else {
     426                /* Deallocate old surface. */
     427                if (old_surface)
     428                        surface_destroy(old_surface);
    374429        }
    375430}
     
    453508                        break;
    454509                case ET_SIGNAL_EVENT:
    455                         handle_signal_event(win, event->data.sig);
     510                        handle_signal_event(win, event->data.signal);
    456511                        break;
    457512                case ET_WINDOW_RESIZE:
    458                         handle_resize(win, event->data.rsz.width, event->data.rsz.height);
     513                        handle_resize(win, event->data.resize.offset_x,
     514                            event->data.resize.offset_y, event->data.resize.width,
     515                            event->data.resize.height, event->data.resize.placement_flags);
    459516                        break;
    460517                case ET_WINDOW_FOCUS:
     
    530587
    531588window_t *window_open(const char *winreg, bool is_main, bool is_decorated,
    532     const char *caption, sysarg_t x_offset, sysarg_t y_offset)
    533 {
    534         int rc;
    535 
     589    const char *caption)
     590{
    536591        window_t *win = (window_t *) malloc(sizeof(window_t));
    537         if (!win) {
     592        if (!win)
    538593                return NULL;
    539         }
    540 
     594       
    541595        win->is_main = is_main;
    542596        win->is_decorated = is_decorated;
     
    544598        prodcons_initialize(&win->events);
    545599        fibril_mutex_initialize(&win->guard);
     600       
    546601        widget_init(&win->root, NULL);
    547602        win->root.window = win;
     
    555610        win->focus = NULL;
    556611        win->surface = NULL;
    557 
     612       
    558613        service_id_t reg_dsid;
    559         async_sess_t *reg_sess;
    560 
    561         rc = loc_service_get_id(winreg, &reg_dsid, 0);
     614        int rc = loc_service_get_id(winreg, &reg_dsid, 0);
    562615        if (rc != EOK) {
    563616                free(win);
    564617                return NULL;
    565618        }
    566 
    567         reg_sess = loc_service_connect(EXCHANGE_SERIALIZE, reg_dsid, 0);
     619       
     620        async_sess_t *reg_sess = loc_service_connect(EXCHANGE_SERIALIZE,
     621            reg_dsid, 0);
    568622        if (reg_sess == NULL) {
    569623                free(win);
    570624                return NULL;
    571625        }
    572 
     626       
    573627        service_id_t in_dsid;
    574628        service_id_t out_dsid;
    575        
    576         rc = win_register(reg_sess, &in_dsid, &out_dsid, x_offset, y_offset);
     629        rc = win_register(reg_sess, &in_dsid, &out_dsid);
    577630        async_hangup(reg_sess);
    578631        if (rc != EOK) {
     
    580633                return NULL;
    581634        }
    582 
     635       
    583636        win->osess = loc_service_connect(EXCHANGE_SERIALIZE, out_dsid, 0);
    584637        if (win->osess == NULL) {
     
    586639                return NULL;
    587640        }
    588 
     641       
    589642        win->isess = loc_service_connect(EXCHANGE_SERIALIZE, in_dsid, 0);
    590643        if (win->isess == NULL) {
     
    593646                return NULL;
    594647        }
    595 
    596         if (caption == NULL) {
     648       
     649        if (caption == NULL)
    597650                win->caption = NULL;
    598         } else {
     651        else
    599652                win->caption = str_dup(caption);
    600         }
    601 
     653       
    602654        return win;
    603655}
    604656
    605 void window_resize(window_t *win, sysarg_t width, sysarg_t height)
     657void window_resize(window_t *win, sysarg_t offset_x, sysarg_t offset_y,
     658    sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags)
    606659{
    607660        window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
     
    609662                link_initialize(&event->link);
    610663                event->type = ET_WINDOW_RESIZE;
    611                 event->data.rsz.width = width;
    612                 event->data.rsz.height = height;
     664                event->data.resize.offset_x = offset_x;
     665                event->data.resize.offset_y = offset_y;
     666                event->data.resize.width = width;
     667                event->data.resize.height = height;
     668                event->data.resize.placement_flags = placement_flags;
    613669                prodcons_produce(&win->events, &event->link);
    614670        }
  • uspace/lib/gui/window.h

    r2e80321 r66be0288  
    6666 * If the window is declared as main, its closure causes termination of the
    6767 * whole application. Note that opened window does not have any surface yet. */
    68 extern window_t *window_open(const char *, bool, bool, const char *, sysarg_t,
    69     sysarg_t);
     68extern window_t *window_open(const char *, bool, bool, const char *);
    7069
    7170/**
     
    7473 * and to paint themselves on the new surface (top-bottom order). Should be
    7574 * called also after opening new window to obtain surface. */
    76 extern void window_resize(window_t *, sysarg_t, sysarg_t);
     75extern void window_resize(window_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
     76    window_placement_flags_t);
    7777
    7878/**
  • uspace/srv/hid/compositor/Makefile

    r2e80321 r66be0288  
    4242
    4343SOURCES = \
    44         compositor.c \
    45         images.c
    46 
    47 IMAGES = \
    48         gfx/nameic.tga
    49 
    50 PRE_DEPEND = images.c images.h
    51 EXTRA_CLEAN = images.c images.h
     44        compositor.c
    5245
    5346include $(USPACE_PREFIX)/Makefile.common
    54 
    55 images.c images.h: $(IMAGES)
    56         $(ROOT_PATH)/tools/mkarray.py images COMPOSITOR_IMAGES $^
  • uspace/srv/hid/compositor/compositor.c

    r2e80321 r66be0288  
    7272#include <codec/tga.h>
    7373
    74 #include "images.h"
    7574#include "compositor.h"
    7675
     
    162161static void input_disconnect(void);
    163162
    164 
    165163static pointer_t *input_pointer(input_t *input)
    166164{
     
    168166}
    169167
    170 static pointer_t *pointer_create()
     168static pointer_t *pointer_create(void)
    171169{
    172170        pointer_t *p = (pointer_t *) malloc(sizeof(pointer_t));
    173         if (!p) {
     171        if (!p)
    174172                return NULL;
    175         }
    176 
     173       
    177174        link_initialize(&p->link);
    178175        p->pos.x = coord_origin;
     
    186183        p->state = 0;
    187184        cursor_init(&p->cursor, CURSOR_DECODER_EMBEDDED, NULL);
    188 
     185       
    189186        /* Ghost window for transformation animation. */
    190187        transform_identity(&p->ghost.transform);
     
    199196        p->accum_ghost.x = 0;
    200197        p->accum_ghost.y = 0;
    201 
     198       
    202199        return p;
    203200}
     
    211208}
    212209
    213 static window_t *window_create(sysarg_t x_offset, sysarg_t y_offset)
     210static window_t *window_create(void)
    214211{
    215212        window_t *win = (window_t *) malloc(sizeof(window_t));
    216         if (!win) {
     213        if (!win)
    217214                return NULL;
    218         }
    219 
     215       
    220216        link_initialize(&win->link);
    221217        atomic_set(&win->ref_cnt, 0);
    222218        prodcons_initialize(&win->queue);
    223219        transform_identity(&win->transform);
    224         transform_translate(&win->transform,
    225             coord_origin + x_offset, coord_origin + y_offset);
    226         win->dx = coord_origin + x_offset;
    227         win->dy = coord_origin + y_offset;
     220        transform_translate(&win->transform, coord_origin, coord_origin);
     221        win->dx = coord_origin;
     222        win->dy = coord_origin;
    228223        win->fx = 1;
    229224        win->fy = 1;
     
    231226        win->opacity = 255;
    232227        win->surface = NULL;
    233 
     228       
    234229        return win;
    235230}
     
    294289    sysarg_t *x_out, sysarg_t *y_out, sysarg_t *w_out, sysarg_t *h_out)
    295290{
    296         if (w_in > 0 && h_in > 0) {
     291        if ((w_in > 0) && (h_in > 0)) {
    297292                sysarg_t x[4];
    298293                sysarg_t y[4];
     294               
    299295                comp_coord_from_client(x_in, y_in, win_trans, &x[0], &y[0]);
    300296                comp_coord_from_client(x_in + w_in - 1, y_in, win_trans, &x[1], &y[1]);
    301297                comp_coord_from_client(x_in + w_in - 1, y_in + h_in - 1, win_trans, &x[2], &y[2]);
    302298                comp_coord_from_client(x_in, y_in + h_in - 1, win_trans, &x[3], &y[3]);
     299               
    303300                (*x_out) = x[0];
    304301                (*y_out) = y[0];
    305302                (*w_out) = x[0];
    306303                (*h_out) = y[0];
    307                 for (int i = 1; i < 4; ++i) {
     304               
     305                for (unsigned int i = 1; i < 4; ++i) {
    308306                        (*x_out) = (x[i] < (*x_out)) ? x[i] : (*x_out);
    309307                        (*y_out) = (y[i] < (*y_out)) ? y[i] : (*y_out);
     
    311309                        (*h_out) = (y[i] > (*h_out)) ? y[i] : (*h_out);
    312310                }
     311               
    313312                (*w_out) = (*w_out) - (*x_out) + 1;
    314313                (*h_out) = (*h_out) - (*y_out) + 1;
     
    321320}
    322321
    323 static void comp_restrict_pointers(void)
     322static void comp_update_viewport_bound_rect(void)
    324323{
    325324        fibril_mutex_lock(&viewport_list_mtx);
    326 
     325       
    327326        sysarg_t x_res = coord_origin;
    328327        sysarg_t y_res = coord_origin;
    329328        sysarg_t w_res = 0;
    330329        sysarg_t h_res = 0;
    331 
     330       
    332331        if (!list_empty(&viewport_list)) {
    333332                viewport_t *vp = (viewport_t *) list_first(&viewport_list);
     
    336335                surface_get_resolution(vp->surface, &w_res, &h_res);
    337336        }
    338 
     337       
    339338        list_foreach(viewport_list, link, viewport_t, vp) {
    340339                sysarg_t w_vp, h_vp;
    341340                surface_get_resolution(vp->surface, &w_vp, &h_vp);
    342                 rectangle_union(
    343                     x_res, y_res, w_res, h_res,
     341                rectangle_union(x_res, y_res, w_res, h_res,
    344342                    vp->pos.x, vp->pos.y, w_vp, h_vp,
    345343                    &x_res, &y_res, &w_res, &h_res);
    346344        }
    347 
     345       
    348346        viewport_bound_rect.x = x_res;
    349347        viewport_bound_rect.y = y_res;
    350348        viewport_bound_rect.w = w_res;
    351349        viewport_bound_rect.h = h_res;
    352 
     350       
    353351        fibril_mutex_unlock(&viewport_list_mtx);
    354 
     352}
     353
     354static void comp_restrict_pointers(void)
     355{
     356        comp_update_viewport_bound_rect();
     357       
    355358        fibril_mutex_lock(&pointer_list_mtx);
    356 
     359       
    357360        list_foreach(pointer_list, link, pointer_t, ptr) {
    358361                ptr->pos.x = ptr->pos.x > viewport_bound_rect.x ? ptr->pos.x : viewport_bound_rect.x;
     
    363366                    ptr->pos.y : viewport_bound_rect.y + viewport_bound_rect.h;
    364367        }
    365 
     368       
    366369        fibril_mutex_unlock(&pointer_list_mtx);
    367370}
     
    642645}
    643646
     647static void comp_recalc_transform(window_t *win)
     648{
     649        transform_t translate;
     650        transform_identity(&translate);
     651        transform_translate(&translate, win->dx, win->dy);
     652       
     653        transform_t scale;
     654        transform_identity(&scale);
     655        if ((win->fx != 1) || (win->fy != 1))
     656                transform_scale(&scale, win->fx, win->fy);
     657       
     658        transform_t rotate;
     659        transform_identity(&rotate);
     660        if (win->angle != 0)
     661                transform_rotate(&rotate, win->angle);
     662       
     663        transform_t transform;
     664        transform_t temp;
     665        transform_identity(&transform);
     666        temp = transform;
     667        transform_multiply(&transform, &temp, &translate);
     668        temp = transform;
     669        transform_multiply(&transform, &temp, &rotate);
     670        temp = transform;
     671        transform_multiply(&transform, &temp, &scale);
     672       
     673        win->transform = transform;
     674}
     675
    644676static void comp_window_resize(window_t *win, ipc_callid_t iid, ipc_call_t *icall)
    645677{
    646         int rc;
    647 
    648678        ipc_callid_t callid;
    649679        size_t size;
    650680        unsigned int flags;
    651 
     681       
    652682        /* Start sharing resized window with client. */
    653683        if (!async_share_out_receive(&callid, &size, &flags)) {
     
    655685                return;
    656686        }
     687       
    657688        void *new_cell_storage;
    658         rc = async_share_out_finalize(callid, &new_cell_storage);
     689        int rc = async_share_out_finalize(callid, &new_cell_storage);
    659690        if ((rc != EOK) || (new_cell_storage == AS_MAP_FAILED)) {
    660691                async_answer_0(iid, ENOMEM);
    661692                return;
    662693        }
    663 
     694       
    664695        /* Create new surface for the resized window. */
    665         surface_t *new_surface = surface_create(
    666             IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall),
    667             new_cell_storage, SURFACE_FLAG_SHARED);
     696        surface_t *new_surface = surface_create(IPC_GET_ARG3(*icall),
     697            IPC_GET_ARG4(*icall), new_cell_storage, SURFACE_FLAG_SHARED);
    668698        if (!new_surface) {
    669699                as_area_destroy(new_cell_storage);
     
    671701                return;
    672702        }
    673 
     703       
     704        sysarg_t offset_x = IPC_GET_ARG1(*icall);
     705        sysarg_t offset_y = IPC_GET_ARG2(*icall);
     706        window_placement_flags_t placement_flags =
     707            (window_placement_flags_t) IPC_GET_ARG5(*icall);
     708       
     709        comp_update_viewport_bound_rect();
     710       
    674711        /* Switch new surface with old surface and calculate damage. */
    675712        fibril_mutex_lock(&window_list_mtx);
    676 
     713       
    677714        sysarg_t old_width = 0;
    678715        sysarg_t old_height = 0;
     716       
    679717        if (win->surface) {
    680718                surface_get_resolution(win->surface, &old_width, &old_height);
    681719                surface_destroy(win->surface);
    682720        }
    683 
     721       
    684722        win->surface = new_surface;
    685 
     723       
    686724        sysarg_t new_width = 0;
    687725        sysarg_t new_height = 0;
    688726        surface_get_resolution(win->surface, &new_width, &new_height);
    689 
    690         sysarg_t x, y;
    691         sysarg_t width = old_width > new_width ? old_width : new_width;
    692         sysarg_t height = old_height > new_height ? old_height : new_height;
    693         comp_coord_bounding_rect(0, 0, width, height, win->transform, &x, &y, &width, &height);
    694 
     727       
     728        if (placement_flags & WINDOW_PLACEMENT_CENTER_X)
     729                win->dx = viewport_bound_rect.x + viewport_bound_rect.w / 2 -
     730                    new_width / 2;
     731       
     732        if (placement_flags & WINDOW_PLACEMENT_CENTER_Y)
     733                win->dy = viewport_bound_rect.y + viewport_bound_rect.h / 2 -
     734                    new_height / 2;
     735       
     736        if (placement_flags & WINDOW_PLACEMENT_LEFT)
     737                win->dx = viewport_bound_rect.x;
     738       
     739        if (placement_flags & WINDOW_PLACEMENT_TOP)
     740                win->dy = viewport_bound_rect.y;
     741       
     742        if (placement_flags & WINDOW_PLACEMENT_RIGHT)
     743                win->dx = viewport_bound_rect.x + viewport_bound_rect.w -
     744                    new_width;
     745       
     746        if (placement_flags & WINDOW_PLACEMENT_BOTTOM)
     747                win->dy = viewport_bound_rect.y + viewport_bound_rect.h -
     748                    new_height;
     749       
     750        if (placement_flags & WINDOW_PLACEMENT_ABSOLUTE_X)
     751                win->dx = coord_origin + offset_x;
     752       
     753        if (placement_flags & WINDOW_PLACEMENT_ABSOLUTE_Y)
     754                win->dy = coord_origin + offset_y;
     755       
     756        /* Transform the window and calculate damage. */
     757        sysarg_t x1;
     758        sysarg_t y1;
     759        sysarg_t width1;
     760        sysarg_t height1;
     761       
     762        comp_coord_bounding_rect(0, 0, old_width, old_height, win->transform,
     763            &x1, &y1, &width1, &height1);
     764       
     765        comp_recalc_transform(win);
     766       
     767        sysarg_t x2;
     768        sysarg_t y2;
     769        sysarg_t width2;
     770        sysarg_t height2;
     771       
     772        comp_coord_bounding_rect(0, 0, new_width, new_height, win->transform,
     773            &x2, &y2, &width2, &height2);
     774       
     775        sysarg_t x;
     776        sysarg_t y;
     777        sysarg_t width;
     778        sysarg_t height;
     779       
     780        rectangle_union(x1, y1, width1, height1, x2, y2, width2, height2,
     781            &x, &y, &width, &height);
     782       
    695783        fibril_mutex_unlock(&window_list_mtx);
    696 
     784       
    697785        comp_damage(x, y, width, height);
    698 
     786       
    699787        async_answer_0(iid, EOK);
    700788}
     
    703791{
    704792        fibril_mutex_lock(&window_list_mtx);
    705 
     793       
    706794        list_foreach(window_list, link, window_t, window) {
    707795                if (window == target) {
     
    711799                }
    712800        }
    713 
     801       
    714802        fibril_mutex_unlock(&window_list_mtx);
    715803        free(event);
     
    719807{
    720808        fibril_mutex_lock(&window_list_mtx);
     809       
    721810        window_t *win = (window_t *) list_first(&window_list);
    722         if (win) {
     811        if (win)
    723812                prodcons_produce(&win->queue, &event->link);
    724         } else {
     813        else
    725814                free(event);
    726         }
     815       
    727816        fibril_mutex_unlock(&window_list_mtx);
    728817}
     
    801890                        fibril_mutex_lock(&window_list_mtx);
    802891
    803                         window_t *win = window_create(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
     892                        window_t *win = window_create();
    804893                        if (!win) {
    805894                                async_answer_2(callid, ENOMEM, 0, 0);
     
    11731262}
    11741263
    1175 static void comp_recalc_transform(window_t *win)
    1176 {
    1177         transform_t translate;
    1178         transform_identity(&translate);
    1179         transform_translate(&translate, win->dx, win->dy);
    1180 
    1181         transform_t scale;
    1182         transform_identity(&scale);
    1183         if (win->fx != 1 || win->fy != 1) {
    1184                 transform_scale(&scale, win->fx, win->fy);
    1185         }
    1186 
    1187         transform_t rotate;
    1188         transform_identity(&rotate);
    1189         if (win->angle != 0) {
    1190                 transform_rotate(&rotate, win->angle);
    1191         }
    1192 
    1193         transform_t transform;
    1194         transform_t temp;
    1195         transform_identity(&transform);
    1196         temp = transform;
    1197         transform_multiply(&transform, &temp, &translate);
    1198         temp = transform;
    1199         transform_multiply(&transform, &temp, &rotate);
    1200         temp = transform;
    1201         transform_multiply(&transform, &temp, &scale);
    1202        
    1203 
    1204         win->transform = transform;
    1205 }
    1206 
    12071264static void comp_window_animate(pointer_t *pointer, window_t *win,
    12081265    sysarg_t *dmg_x, sysarg_t *dmg_y, sysarg_t *dmg_width, sysarg_t *dmg_height)
     
    12261283                double cx = 0;
    12271284                double cy = 0;
    1228                 if (pointer->grab_flags & GF_MOVE_X) {
     1285               
     1286                if (pointer->grab_flags & GF_MOVE_X)
    12291287                        cx = 1;
    1230                 }
    1231                 if (pointer->grab_flags & GF_MOVE_Y) {
     1288               
     1289                if (pointer->grab_flags & GF_MOVE_Y)
    12321290                        cy = 1;
    1233                 }
    1234 
    1235                 if ((scale || resize) && (win->angle != 0)) {
     1291               
     1292                if (((scale) || (resize)) && (win->angle != 0)) {
    12361293                        transform_t rotate;
    12371294                        transform_identity(&rotate);
     1295                       
    12381296                        transform_rotate(&rotate, win->angle);
    12391297                        transform_apply_linear(&rotate, &cx, &cy);
    12401298                }
    12411299               
    1242                 cx = (cx < 0) ? (-1 * cx) : cx; 
     1300                cx = (cx < 0) ? (-1 * cx) : cx;
    12431301                cy = (cy < 0) ? (-1 * cy) : cy;
    1244 
     1302               
    12451303                win->dx += (cx * dx);
    12461304                win->dy += (cy * dy);
    12471305        }
    12481306
    1249         if (scale || resize) {
     1307        if ((scale) || (resize)) {
    12501308                double _dx = dx;
    12511309                double _dy = dy;
     
    12631321                        if (fx > 0) {
    12641322#if ANIMATE_WINDOW_TRANSFORMS == 0
    1265                                 if (scale) win->fx *= fx;
     1323                                if (scale)
     1324                                        win->fx *= fx;
    12661325#endif
    12671326#if ANIMATE_WINDOW_TRANSFORMS == 1
     
    14441503{
    14451504        pointer_t *pointer = input_pointer(input);
    1446 
     1505       
     1506        comp_update_viewport_bound_rect();
     1507       
    14471508        /* Update pointer position. */
    14481509        fibril_mutex_lock(&pointer_list_mtx);
     1510       
    14491511        desktop_point_t old_pos = pointer->pos;
     1512       
    14501513        sysarg_t cursor_width;
    14511514        sysarg_t cursor_height;
    1452         surface_get_resolution(pointer->cursor.states[pointer->state], 
     1515        surface_get_resolution(pointer->cursor.states[pointer->state],
    14531516             &cursor_width, &cursor_height);
    1454         if (pointer->pos.x + dx < viewport_bound_rect.x) {
     1517       
     1518        if (pointer->pos.x + dx < viewport_bound_rect.x)
    14551519                dx = -1 * (pointer->pos.x - viewport_bound_rect.x);
    1456         }
    1457         if (pointer->pos.y + dy < viewport_bound_rect.y) {
     1520       
     1521        if (pointer->pos.y + dy < viewport_bound_rect.y)
    14581522                dy = -1 * (pointer->pos.y - viewport_bound_rect.y);
    1459         }
    1460         if (pointer->pos.x + dx > viewport_bound_rect.x + viewport_bound_rect.w) {
     1523       
     1524        if (pointer->pos.x + dx > viewport_bound_rect.x + viewport_bound_rect.w)
    14611525                dx = (viewport_bound_rect.x + viewport_bound_rect.w - pointer->pos.x);
    1462         }
    1463         if (pointer->pos.y + dy > viewport_bound_rect.y + viewport_bound_rect.h) {
     1526       
     1527        if (pointer->pos.y + dy > viewport_bound_rect.y + viewport_bound_rect.h)
    14641528                dy = (viewport_bound_rect.y + viewport_bound_rect.h - pointer->pos.y);
    1465         }
     1529       
    14661530        pointer->pos.x += dx;
    14671531        pointer->pos.y += dy;
     
    14691533        comp_damage(old_pos.x, old_pos.y, cursor_width, cursor_height);
    14701534        comp_damage(old_pos.x + dx, old_pos.y + dy, cursor_width, cursor_height);
    1471 
     1535       
    14721536        fibril_mutex_lock(&window_list_mtx);
    14731537        fibril_mutex_lock(&pointer_list_mtx);
     
    16301694
    16311695#if ANIMATE_WINDOW_TRANSFORMS == 0
    1632                 sysarg_t pre_x = 0; 
     1696                sysarg_t pre_x = 0;
    16331697                sysarg_t pre_y = 0;
    16341698                sysarg_t pre_width = 0;
     
    16621726                                link_initialize(&event_top->link);
    16631727                                event_top->type = ET_WINDOW_RESIZE;
    1664 
     1728                               
     1729                                event_top->data.resize.offset_x = 0;
     1730                                event_top->data.resize.offset_y = 0;
     1731                               
    16651732                                int dx = (int) (((double) width) * (scale_back_x - 1.0));
    16661733                                int dy = (int) (((double) height) * (scale_back_y - 1.0));
    1667 
    1668                                 if (pointer->grab_flags & GF_RESIZE_X) {
    1669                                         event_top->data.rsz.width =
    1670                                                 ((((int) width) + dx) >= 0) ? (width + dx) : 0;
    1671                                 } else {
    1672                                         event_top->data.rsz.width = width;
    1673                                 }
    1674 
    1675                                 if (pointer->grab_flags & GF_RESIZE_Y) {
    1676                                         event_top->data.rsz.height =
    1677                                                 ((((int) height) + dy) >= 0) ? (height + dy) : 0;
    1678                                 } else {
    1679                                         event_top->data.rsz.height = height;
    1680                                 }
     1734                               
     1735                                if (pointer->grab_flags & GF_RESIZE_X)
     1736                                        event_top->data.resize.width =
     1737                                            ((((int) width) + dx) >= 0) ? (width + dx) : 0;
     1738                                else
     1739                                        event_top->data.resize.width = width;
     1740                               
     1741                                if (pointer->grab_flags & GF_RESIZE_Y)
     1742                                        event_top->data.resize.height =
     1743                                            ((((int) height) + dy) >= 0) ? (height + dy) : 0;
     1744                                else
     1745                                        event_top->data.resize.height = height;
     1746                               
     1747                                event_top->data.resize.placement_flags =
     1748                                    WINDOW_PLACEMENT_ANY;
    16811749                        }
    16821750
     
    17461814            key == KC_O || key == KC_P);
    17471815        bool kconsole_switch = (mods & KM_ALT) && (key == KC_M);
    1748         bool compositor_test = (mods & KM_ALT) && (key == KC_H);
    17491816
    17501817        bool filter = (type == KEY_RELEASE) && (win_transform || win_resize ||
    17511818            win_opacity || win_close || win_switch || viewport_move ||
    1752             viewport_change || kconsole_switch || compositor_test);
     1819            viewport_change || kconsole_switch);
    17531820
    17541821        if (filter) {
     
    18161883                                return ENOMEM;
    18171884                        }
    1818 
     1885                       
    18191886                        sysarg_t width, height;
    18201887                        surface_get_resolution(win->surface, &width, &height);
    1821 
     1888                       
    18221889                        link_initialize(&event->link);
    18231890                        event->type = ET_WINDOW_RESIZE;
    1824 
     1891                       
     1892                        event->data.resize.offset_x = 0;
     1893                        event->data.resize.offset_y = 0;
     1894                       
    18251895                        switch (key) {
    18261896                        case KC_T:
    1827                                 event->data.rsz.width = width;
    1828                                 event->data.rsz.height = (height >= 20) ? height - 20 : 0;
     1897                                event->data.resize.width = width;
     1898                                event->data.resize.height = (height >= 20) ? height - 20 : 0;
    18291899                                break;
    18301900                        case KC_G:
    1831                                 event->data.rsz.width = width;
    1832                                 event->data.rsz.height = height + 20;
     1901                                event->data.resize.width = width;
     1902                                event->data.resize.height = height + 20;
    18331903                                break;
    18341904                        case KC_B:
    1835                                 event->data.rsz.width = (width >= 20) ? width - 20 : 0;;
    1836                                 event->data.rsz.height = height;
     1905                                event->data.resize.width = (width >= 20) ? width - 20 : 0;;
     1906                                event->data.resize.height = height;
    18371907                                break;
    18381908                        case KC_N:
    1839                                 event->data.rsz.width = width + 20;
    1840                                 event->data.rsz.height = height;
     1909                                event->data.resize.width = width + 20;
     1910                                event->data.resize.height = height;
    18411911                                break;
    18421912                        default:
    1843                                 event->data.rsz.width = 0;
    1844                                 event->data.rsz.height = 0;
    1845                                 break;
    1846                         }
    1847 
     1913                                event->data.resize.width = 0;
     1914                                event->data.resize.height = 0;
     1915                                break;
     1916                        }
     1917                       
     1918                        event->data.resize.placement_flags = WINDOW_PLACEMENT_ANY;
     1919                       
    18481920                        fibril_mutex_unlock(&window_list_mtx);
    18491921                        comp_post_event_top(event);
     
    20142086        } else if (kconsole_switch) {
    20152087                __SYSCALL0(SYS_DEBUG_ACTIVATE_CONSOLE);
    2016         } else if (compositor_test) {
    2017                 fibril_mutex_lock(&window_list_mtx);
    2018 
    2019                 window_t *red_win = window_create(0, 0);
    2020                 red_win->surface = surface_create(250, 150, NULL, 0);
    2021                 pixel_t red_pix = PIXEL(255, 240, 0, 0);
    2022                 for (sysarg_t y = 0; y <  150; ++y) {
    2023                         for (sysarg_t x = 0; x < 250; ++x) {
    2024                                 surface_put_pixel(red_win->surface, x, y, red_pix);
    2025                         }
    2026                 }
    2027                 list_prepend(&red_win->link, &window_list);
    2028 
    2029                 window_t *blue_win = window_create(0, 0);
    2030                 blue_win->surface = surface_create(200, 100, NULL, 0);
    2031                 pixel_t blue_pix = PIXEL(255, 0, 0, 240);
    2032                 for (sysarg_t y = 0; y <  100; ++y) {
    2033                         for (sysarg_t x = 0; x < 200; ++x) {
    2034                                 surface_put_pixel(blue_win->surface, x, y, blue_pix);
    2035                         }
    2036                 }
    2037                 list_prepend(&blue_win->link, &window_list);
    2038                
    2039                 window_t *nameic_win = window_create(0, 0);
    2040                 nameic_win->surface = decode_tga((void *) nameic_tga, nameic_tga_size, 0);
    2041                 list_prepend(&nameic_win->link, &window_list);
    2042 
    2043                 fibril_mutex_unlock(&window_list_mtx);
    2044                 comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
    20452088        } else {
    20462089                window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
  • uspace/srv/logger/writer.c

    r2e80321 r66be0288  
    4040#include <io/log.h>
    4141#include <io/logctl.h>
     42#include <io/klog.h>
    4243#include <ns.h>
    4344#include <async.h>
     
    7980        }
    8081
    81         printf("[%s] %s: %s\n",
     82        KLOG_PRINTF(level, "[%s] %s: %s\n",
    8283            log->full_name, log_level_str(level),
    8384            (const char *) message);
Note: See TracChangeset for help on using the changeset viewer.