For most users of the Elementary A\+P\+I, the \hyperlink{group__Win}{Win} widget has a lot more functions than what they need.

In general, a developer will create a window, set some content on it and forget about it for the rest of its program\textquotesingle{}s life, letting whatever Window Manager is there to handle the window. Here, however, we are going to show how to generally manage a window.

We\textquotesingle{}ll have a bit more than the usual includes here, since part of the example requires some low level fiddling.  
\begin{DoxyCodeInclude}
\textcolor{preprocessor}{#ifdef HAVE\_ELEMENTARY\_X}
\textcolor{preprocessor}{# include <Ecore\_X.h>}
\textcolor{preprocessor}{#endif}

\textcolor{preprocessor}{#include <Elementary.h>}

\end{DoxyCodeInclude}


The program then, consists of one window with two lists of buttons, each of which operates on another two windows. One of them is a normal window, the other has the {\ttfamily override} flag set so the Window Manager ignores it.

Pressing each button will call the corresponding function to act on the corresponding window. These are pretty self explanatory, so we\textquotesingle{}ll show them in one batch. 
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_activate\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   elm_win_activate(data);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_lower\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   elm_win_lower(data);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_raise\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   elm_win_raise(data);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_borderless\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   Eina\_Bool flag = elm_win_borderless_get(data);
   elm_win_borderless_set(data, !flag);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_shaped\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   Eina\_Bool flag = elm_win_shaped_get(data);
   elm_win_shaped_set(data, !flag);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_alpha\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   Eina\_Bool flag = elm_win_alpha_get(data);
   elm_win_alpha_set(data, !flag);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_fullscreen\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   Eina\_Bool flag = elm_win_fullscreen_get(data);
   elm_win_fullscreen_set(data, !flag);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_maximized\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   Eina\_Bool flag = elm_win_maximized_get(data);
   elm_win_maximized_set(data, !flag);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_iconified\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   Eina\_Bool flag = elm_win_iconified_get(data);
   elm_win_iconified_set(data, !flag);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_rotation\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   \textcolor{keywordtype}{int} angle = elm_win_rotation_get(data);
   angle = (angle + 90) % 360;
   elm_win_rotation_set(data, angle);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_rotation\_resize\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   \textcolor{keywordtype}{int} angle = elm_win_rotation_get(data);
   angle = (angle + 90) % 360;
   elm_win_rotation_with_resize_set(data, angle);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_btn\_sticky\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   Eina\_Bool flag = elm_win_sticky_get(data);
   elm_win_sticky_set(data, !flag);
\}

\end{DoxyCodeInclude}


Next, we handle the main window closing. We have a {\ttfamily \char`\"{}delete,request\char`\"{}} callback set to ask if really want to quit. If so, we end the main loop, otherwise just delete the popup message and continue running normally. 
\begin{DoxyCodeInclude}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_yes\_quit\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   elm_exit();
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_no\_quit\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   evas\_object\_del(data);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_main\_win\_del\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   Evas\_Object *msg, *box, *box2, *btn, *lbl, *sep;

   msg = elm_notify_add(obj);
   elm_notify_align_set(msg, 0.5, 0.5);
   elm_notify_allow_events_set(msg, EINA\_FALSE);
   evas\_object\_show(msg);

   box = elm_box_add(obj);
   evas\_object\_size\_hint\_weight\_set(box, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(box, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm\_object\_content\_set(msg, box);
   evas\_object\_show(box);

   lbl = elm_label_add(obj);
   elm\_object\_text\_set(lbl, \textcolor{stringliteral}{"Really want quit?"});
   evas\_object\_size\_hint\_weight\_set(lbl, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(lbl, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(box, lbl);
   evas\_object\_show(lbl);

   sep = elm_separator_add(obj);
   elm_separator_horizontal_set(sep, EINA\_TRUE);
   elm_box_pack_end(box, sep);
   evas\_object\_show(sep);

   box2 = elm_box_add(obj);
   elm_box_horizontal_set(box2, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(box2, EVAS\_HINT\_EXPAND, 0.0);
   evas\_object\_size\_hint\_align\_set(box2, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(box, box2);
   evas\_object\_show(box2);

   btn = elm_button_add(obj);
   elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Yes"});
   elm_box_pack_end(box2, btn);
   evas\_object\_show(btn);

   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"clicked"}, \_yes\_quit\_cb, NULL);

   btn = elm_button_add(obj);
   elm\_object\_text\_set(btn, \textcolor{stringliteral}{"No"});
   elm_box_pack_end(box2, btn);
   evas\_object\_show(btn);

   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"clicked"}, \_no\_quit\_cb, msg);
\}

\end{DoxyCodeInclude}


The non-\/managed window, being completely ignored by the Window Manager, is likely to never receive keyboard focus, even if we click on its entry to write something. So we have a button on it that will forcefully focus it by using some lower level functions to act directly on the X window. Then, each time one of the window is focused, we print some message on a console to show this more clearly. 
\begin{DoxyCodeInclude}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_force\_focus\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
\textcolor{preprocessor}{#ifdef HAVE\_ELEMENTARY\_X}
   Ecore\_X\_Window xwin = elm_win_xwindow_get(data);
   ecore\_x\_window\_focus(xwin);
\textcolor{preprocessor}{#endif}
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_win\_focused\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name = data;
   printf(\textcolor{stringliteral}{"Window focused: %s\(\backslash\)n"}, name);
\}

\end{DoxyCodeInclude}


And to finalize, the main function creates a window to hold all the action buttons and another two to show how (and what) works on each of them.

First, the main window will be a normal window, we\textquotesingle{}ll enable the focus highlight regardless of how it is configured so it\textquotesingle{}s easier to navigate the window with the keyboard. Then we hook our focus and delete callbacks and set up the rest of the window\textquotesingle{}s content. 
\begin{DoxyCodeInclude}

\textcolor{keyword}{static} Eina\_Bool
key\_down()
\{
   elm_win_fullscreen_set(win2, 0);

   \textcolor{keywordflow}{return} ECORE\_CALLBACK\_PASS\_ON;
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} *argv[])
\{
   Evas\_Object *win, *bigbox, *box, *btn, *o;
   \textcolor{keywordtype}{char} buf[256];

   elm_app_info_set(elm\_main, \textcolor{stringliteral}{"elementary"}, \textcolor{stringliteral}{"images/logo.png"});

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"win-example"}, \textcolor{stringliteral}{"Elm\_Win Example"});
   elm_win_focus_highlight_enabled_set(win, EINA\_TRUE);

   evas\_object\_smart\_callback\_add(win, \textcolor{stringliteral}{"focus,in"}, \_win\_focused\_cb, \textcolor{stringliteral}{"mainwin"});

   evas\_object\_smart\_callback\_add(win, \textcolor{stringliteral}{"delete,request"}, \_main\_win\_del\_cb,
                                  NULL);

   ecore\_event\_handler\_add(ECORE\_EVENT\_KEY\_DOWN, key\_down, NULL);

   bigbox = elm_box_add(win);
   elm_box_horizontal_set(bigbox, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(bigbox, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_win_resize_object_add(win, bigbox);
   evas\_object\_show(bigbox);

   box = elm_box_add(win);
   evas\_object\_size\_hint\_weight\_set(box, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(box, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(bigbox, box);
   evas\_object\_show(box);

\end{DoxyCodeInclude}


The first of our sub-\/windows is the managed one. We\textquotesingle{}ll create it as a dialog, which should make the Window Manager treat it as a non-\/resizable window. We are also setting the window to be auto-\/deleted when the close button in the titlebar is pressed. 
\begin{DoxyCodeInclude}

   win2 = elm_win_add(NULL, \textcolor{stringliteral}{"sub-win-example"}, ELM_WIN_DIALOG_BASIC);
   elm_win_autodel_set(win2, EINA\_TRUE);
   elm_win_title_set(win2, \textcolor{stringliteral}{"Managed window"});
   evas\_object\_show(win2);

   evas\_object\_smart\_callback\_add(win2, \textcolor{stringliteral}{"focus,in"}, \_win\_focused\_cb, \textcolor{stringliteral}{"managed"});

   o = elm_icon_add(win2);
   sprintf(buf, \textcolor{stringliteral}{"%s/images/logo.png"}, elm_app_data_dir_get());
   elm_image_file_set(o, buf, NULL);
   elm_image_resizable_set(o, EINA\_FALSE, EINA\_FALSE);
   elm_image_no_scale_set(o, EINA\_TRUE);
   elm_win_resize_object_add(win2, o);
   evas\_object\_show(o);

\end{DoxyCodeInclude}


Now, we added an icon to the window as a resize object. We also set this icon to not scale, and no weight size hints have been set for it. This way, even if we hadn\textquotesingle{}t created the window as a dialog, it would still not be resizable. The window size is defined by its content, so it would never be smaller than the smallest of its resize objects, and for it to be resizable, all of those objects have to allow it.

Next, we add the buttons with the actions to perform on this window. Using a macro saves us typing and makes the world a happier place. 
\begin{DoxyCodeInclude}

   o = elm_label_add(win);
   elm\_object\_text\_set(o, \textcolor{stringliteral}{"<b>Managed Window</b>"});
   elm_box_pack_end(box, o);
   evas\_object\_show(o);

\textcolor{preprocessor}{#define WIN\_ACTION(name) \(\backslash\)}
\textcolor{preprocessor}{   do \{ \(\backslash\)}
\textcolor{preprocessor}{        btn = elm\_button\_add(win); \(\backslash\)}
\textcolor{preprocessor}{        elm\_object\_text\_set(btn, #name); \(\backslash\)}
\textcolor{preprocessor}{        elm\_box\_pack\_end(box, btn); \(\backslash\)}
\textcolor{preprocessor}{        evas\_object\_show(btn); \(\backslash\)}
\textcolor{preprocessor}{        evas\_object\_smart\_callback\_add(btn, "clicked", \_btn\_##name##\_cb, win2); \(\backslash\)}
\textcolor{preprocessor}{   \} while (0)}

   WIN\_ACTION(activate);
   WIN\_ACTION(lower);
   WIN\_ACTION(\textcolor{keyword}{raise});
   WIN\_ACTION(borderless);
   WIN\_ACTION(shaped);
   WIN\_ACTION(alpha);
   WIN\_ACTION(fullscreen);
   WIN\_ACTION(maximized);
   WIN\_ACTION(iconified);
   WIN\_ACTION(rotation);
   WIN\_ACTION(rotation\_resize);
   WIN\_ACTION(sticky);

\end{DoxyCodeInclude}


The maximize one is likely to not work, because the Window Manager will probably not enforce it upon a window that states its maximum size, much less a dialog. But that can be changed by editting the example to use \hyperlink{group__Win_gga4df03d1a1e94e8b24a58d8ccc5d4d514a505928a16effb6fff3caa009a7d306b7}{E\+L\+M\+\_\+\+W\+I\+N\+\_\+\+B\+A\+S\+I\+C} when creating the window and adding the following line to the icon set as content 
\begin{DoxyCode}
evas\_object\_size\_hint\_weight\_set(o, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
\end{DoxyCode}


Lastly, the second sub-\/window will have it\textquotesingle{}s override flag set. In it we have a label with some text, and entry and a button. The entry can be clicked normally to set focus on it, but whether it actually gets keyboard input will also depend on the window getting focus, and since the window is an override one, it will probably not gain it by normal means. The button is there to force the focus at the X level to go to our window. And to finish, another list of buttons with actions to perform on this last window. Remember that most of them are requests or hints for the Window Manager, so they are likely to do nothing on this window. Similarly, there won\textquotesingle{}t be any way to move it or resize it, because we haven\textquotesingle{}t implemented that kind of control on this example and that\textquotesingle{}s something controlled by Window Managers on windows they are tracking, which is not the case with this one. 
\begin{DoxyCodeInclude}

   box = elm_box_add(win);
   evas\_object\_size\_hint\_weight\_set(box, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(box, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(bigbox, box);
   evas\_object\_show(box);

   win2 = elm_win_util_standard_add(\textcolor{stringliteral}{"sub-win-example2"}, \textcolor{stringliteral}{"Non-managed window"});
   elm_win_autodel_set(win2, EINA\_TRUE);
   elm_win_override_set(win2, EINA\_TRUE);
   evas\_object\_show(win2);

   evas\_object\_smart\_callback\_add(win2, \textcolor{stringliteral}{"focus,in"}, \_win\_focused\_cb,
                                  \textcolor{stringliteral}{"override"});

   bigbox = elm_box_add(win2);
   evas\_object\_size\_hint\_weight\_set(bigbox, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_win_resize_object_add(win2, bigbox);
   evas\_object\_show(bigbox);

   o = elm_label_add(win2);
   elm\_object\_text\_set(o, \textcolor{stringliteral}{"This window should have no borders or titlebar.<ps>"}
                       \textcolor{stringliteral}{"It was set in override mode, so the Window Manager<ps>"}
                       \textcolor{stringliteral}{"should ignore everything about it.<ps>"}
                       \textcolor{stringliteral}{"It's up to the program to handle it properly, and some"}
                       \textcolor{stringliteral}{"of the actions performed on it may not have any effect."}
                      );
   elm_box_pack_end(bigbox, o);
   evas\_object\_show(o);

   o = elm_entry_add(win2);
   elm\_object\_text\_set(o, \textcolor{stringliteral}{"See if you can focus me"});
   elm_entry_single_line_set(o, EINA\_TRUE);
   elm_entry_scrollable_set(o, EINA\_TRUE);
   evas\_object\_size\_hint\_weight\_set(o, EVAS\_HINT\_EXPAND, 0.0);
   evas\_object\_size\_hint\_align\_set(o, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(bigbox, o);
   evas\_object\_show(o);

   o = elm_separator_add(win2);
   elm_separator_horizontal_set(o, EINA\_TRUE);
   elm_box_pack_end(bigbox, o);
   evas\_object\_show(o);

   o = elm_button_add(win2);
   elm\_object\_text\_set(o, \textcolor{stringliteral}{"Focus me"});
   elm_box_pack_end(bigbox, o);
   evas\_object\_show(o);

   evas\_object\_smart\_callback\_add(o, \textcolor{stringliteral}{"clicked"}, \_force\_focus\_cb, win2);

   o = elm_label_add(win);
   elm\_object\_text\_set(o, \textcolor{stringliteral}{"<b>Override Window</b>"});
   elm_box_pack_end(box, o);
   evas\_object\_show(o);

   WIN\_ACTION(activate);
   WIN\_ACTION(lower);
   WIN\_ACTION(\textcolor{keyword}{raise});
   WIN\_ACTION(borderless);
   WIN\_ACTION(shaped);
   WIN\_ACTION(alpha);
   WIN\_ACTION(fullscreen);
   WIN\_ACTION(maximized);
   WIN\_ACTION(iconified);
   WIN\_ACTION(rotation);
   WIN\_ACTION(rotation\_resize);
   WIN\_ACTION(sticky);

   evas\_object\_resize(win, 400, 400);
   evas\_object\_show(win);

   elm_run();

   \textcolor{keywordflow}{return} 0;
\}
ELM_MAIN()

\end{DoxyCodeInclude}


The full code listing of this example can be found at \hyperlink{win_example_8c-example}{win\+\_\+example.c}. 