1 | /*
|
---|
2 | * Copyright (c) 2012 Petr Koupy
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup gui
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /**
|
---|
33 | * @file
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef GUI_WINDOW_H_
|
---|
37 | #define GUI_WINDOW_H_
|
---|
38 |
|
---|
39 | #include <async.h>
|
---|
40 | #include <adt/prodcons.h>
|
---|
41 | #include <fibril_synch.h>
|
---|
42 | #include <ipc/window.h>
|
---|
43 | #include <io/window.h>
|
---|
44 | #include <surface.h>
|
---|
45 |
|
---|
46 | #include "widget.h"
|
---|
47 |
|
---|
48 | struct window {
|
---|
49 | bool is_main; /**< True for the main window of the application. */
|
---|
50 | bool is_decorated; /**< True if the window decorations should be rendered. */
|
---|
51 | bool is_focused; /**< True for the top level window of the desktop. */
|
---|
52 | char *caption; /**< Text title of the window header. */
|
---|
53 | async_sess_t *isess; /**< Input events from compositor. */
|
---|
54 | async_sess_t *osess; /**< Mainly for damage reporting to compositor. */
|
---|
55 | prodcons_t events; /**< Queue for window event loop. */
|
---|
56 | widget_t root; /**< Decoration widget serving as a root of widget hiearchy. */
|
---|
57 | widget_t *grab; /**< Widget owning the mouse or NULL. */
|
---|
58 | widget_t *focus; /**< Widget owning the keyboard or NULL. */
|
---|
59 | fibril_mutex_t guard; /**< Mutex guarding window surface. */
|
---|
60 | surface_t *surface; /**< Window surface shared with compositor. */
|
---|
61 | };
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Allocate all resources for new window and register it in the compositor.
|
---|
65 | * If the window is declared as main, its closure causes termination of the
|
---|
66 | * whole application. Note that opened window does not have any surface yet.
|
---|
67 | */
|
---|
68 | extern window_t *window_open(const char *, const void *, window_flags_t,
|
---|
69 | const char *);
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Post resize event into event loop. Window negotiates new surface with
|
---|
73 | * compositor and asks all widgets in the tree to calculate their new properties
|
---|
74 | * and to paint themselves on the new surface (top-bottom order). Should be
|
---|
75 | * called also after opening new window to obtain surface. */
|
---|
76 | extern void window_resize(window_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
|
---|
77 | window_placement_flags_t);
|
---|
78 |
|
---|
79 | /** Change window caption. */
|
---|
80 | extern int window_set_caption(window_t *, const char *);
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Post refresh event into event loop. Widget tree is traversed and all widgets
|
---|
84 | * are asked to repaint themselves in top-bottom order. Should be called by
|
---|
85 | * widget after such change of its internal state that does not need resizing
|
---|
86 | * of neither parent nor children (). */
|
---|
87 | extern void window_refresh(window_t *);
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Post damage event into event loop. Handler informs compositor to update the
|
---|
91 | * window surface on the screen. Should be called by widget after painting
|
---|
92 | * itself or copying its buffer onto window surface. */
|
---|
93 | extern void window_damage(window_t *);
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Retrieve dummy root widget of the window widget tree. Intended to be called
|
---|
97 | * by proper top-level widget to set his parent. */
|
---|
98 | extern widget_t *window_root(window_t *);
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Prepare and enqueue window fibrils for event loop and input fetching. When
|
---|
102 | * async_manager() function is called, event loop is executed. */
|
---|
103 | extern void window_exec(window_t *);
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Claim protected window surface. Intended for widgets painting from their
|
---|
107 | * internal fibrils (e.g. terminal, animation, video). */
|
---|
108 | extern surface_t *window_claim(window_t *);
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Yield protected window surface after painting. */
|
---|
112 | extern void window_yield(window_t *);
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Initiate the closing cascade for the window. First, compositor deallocates
|
---|
116 | * output resources, prepares special closing input event for the window and
|
---|
117 | * deallocates input resources after the event is dispatched. When window
|
---|
118 | * fetches closing event, it is posted into event loop and input fibril
|
---|
119 | * terminates. When event loop fibril handles closing event, all window
|
---|
120 | * resources are deallocated and fibril also terminates. Moreover, if the
|
---|
121 | * window is main window of the application, whole task terminates. */
|
---|
122 | extern void window_close(window_t *);
|
---|
123 |
|
---|
124 | #endif
|
---|
125 |
|
---|
126 | /** @}
|
---|
127 | */
|
---|