[virt-tools-list] [PATCH 4/5] window: Replace toolbar with headerbar (fullscreen)

Fabiano Fidêncio fidencio at redhat.com
Sat Dec 17 16:50:11 UTC 2016


From: Sagar Ghuge <ghugesss at gmail.com>

In order to give a modern look to {virt,remote}-viewer let's replace the
old toolbar for a headerbar (it's the widget shown when the app is
fullscreen).

The items in the headerbar are exactly the same ones present in the old
toolbar.

Signed-off-by: Sagar Ghuge <ghugesss at gmail.com>
---
 icons/24x24/Makefile.am                 |   4 -
 icons/24x24/virt-viewer-usb.png         | Bin 1063 -> 0 bytes
 icons/24x24/virt-viewer-usb.svg         | 204 ---------------------
 src/resources/ui/virt-viewer.ui         |  62 +++++++
 src/resources/virt-viewer.gresource.xml |   1 -
 src/virt-viewer-app.c                   |   2 +-
 src/virt-viewer-timed-revealer.c        |   2 +-
 src/virt-viewer-window.c                | 311 ++++----------------------------
 src/virt-viewer-window.h                |   2 +-
 9 files changed, 105 insertions(+), 483 deletions(-)
 delete mode 100644 icons/24x24/virt-viewer-usb.png
 delete mode 100644 icons/24x24/virt-viewer-usb.svg

diff --git a/icons/24x24/Makefile.am b/icons/24x24/Makefile.am
index f2b6388..85f7553 100644
--- a/icons/24x24/Makefile.am
+++ b/icons/24x24/Makefile.am
@@ -5,8 +5,4 @@ apps_icondir = $(datadir)/icons/hicolor/$(size)/apps/
 apps_icon_DATA = $(PACKAGE).png
 EXTRA_DIST += $(apps_icon_DATA)
 
-devices_icondir = $(datadir)/icons/hicolor/$(size)/devices/
-devices_icon_DATA = virt-viewer-usb.png virt-viewer-usb.svg
-EXTRA_DIST += $(devices_icon_DATA)
-
 -include $(top_srcdir)/git.mk
diff --git a/icons/24x24/virt-viewer-usb.png b/icons/24x24/virt-viewer-usb.png
deleted file mode 100644
index e23661e402387bd2601c634860d2627b0aebe721..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 1063
zcmV+?1laqDP)<h;3K|Lk000e1NJLTq000;O000;W1^@s6;CDUv00006VoOIv0RI60
z0RN!9r;`8x1KdeOK~zYIm6lCtTvZgufA`)uv9=~5H8!DOT3ZV#;-;lk5|a`XQK1Vz
zz=f7tUFpu9;L;c?f}1YfDNPYU3A#vwh#&Q%X)SS~p|wpi+N8-OO){OAbdt`z`{m-z
zymXS8Ko1;v at 6Y-CpL@@HVsv!0Mb`N<c;AI!3xM|?Aq4j#6+WH<@Qc&(c;Hp^MN>md
zPeXm91VPzG2!Z!y#~3?1Jb?h7?|8HnG`15Wwku=cw=CzEo?gf<d>KTM?yi5JQLe78
zBu3R_G`+~l)4u`Gv`z8&-sVj^s^8Y2GIP^UN^4yTJl0yAb5(UAT%ouB0>*ia^Yr##
zU?E(oY44l^z*?7*#u&T at Yi(66M4I0ION4oilnN;oVLrwRk*?|IJs4vMv^D at q*7fq)
z&=tm}myk+U;A7KEd_HuA!Hbg>__yyrmpp522%NRV6je{~&MSv`??ev(oo}51;QXh@
z09ajJ<?N;D3j4J<9%n6qu`xx?*{TV0xm)CNw*Zhz0WdQY2MzO4f|aEl$9pi=5NNF{
zGF#^vIDdoTtBU}1v^Voo=ffx|5K<+!;fkj3tIG+tu>;Ur6If$$&L)`$hG!TYnM;fY
zN9I5XUhdeLRGZ5e_-J69xiF%wwUJNW?xwlnegLMXt|y&XQ=-T at mt?*;wv1d?)gR*_
zFC1=7 at Q=Sq$H7|~Ir-)jtcLUam#w7OITur8w81&QHUlXUvhu_ at 6wcWMpA940S{mp(
zafrh0d92+yKj%C~8>BHNZpX%5Jae!OsZ at pDSC=A}*U9^?)<!;j;}9$1O`=FAzIUs0
zcI_U-U|hw~gAbvU;=4bm@!nGxC>ECsocew)8R!Sc53rn_#Tc`p^1FwvwIQ(9U`ulV
z$S%%v^uP{Y>)8zm@^>QozP`fcsW2IGxG=M6 at HjynH!#LvjIH1?lgW_DWJ)8Ey!+xl
zP7O^mGLZ$KSS)TD9Ke{EBB`||o<sGeWsKp*<aJt`QV69GO7Y{>J0+fLt1%|N2gaDv
zf~vkM0Dc<R{QmE4Wa$*0o6uMXJ^NCdP*fUnOp&R%DggevDG=*c!r$|PBYSK6l;Z~F
zRyOM(6{J{qH3(FIwYsKHnR*!~h>~?tO}pB+BT5&rtX=!JZ|b9U6n9{?(Zymh<(#ki
z$vm=0BIFK!{U_e4-TNP;d$%VuUA=1|1jS;6)h-IW=iGRDtmlzkdjcsXQp!@IwI6_`
z+#=7m at 8s3a#{kG?v&_zB*t#`daHS7DLWtxPji;{}@9ob)v0#p+)9KS=W7nPnf|{h>
hn;50k58lex{|8sH2#IslN<07n002ovPDHLkV1iv){{;X5

diff --git a/icons/24x24/virt-viewer-usb.svg b/icons/24x24/virt-viewer-usb.svg
deleted file mode 100644
index 4101f6e..0000000
--- a/icons/24x24/virt-viewer-usb.svg
+++ /dev/null
@@ -1,204 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!-- Created with Inkscape (http://www.inkscape.org/) -->
-
-<svg
-   xmlns:dc="http://purl.org/dc/elements/1.1/"
-   xmlns:cc="http://creativecommons.org/ns#"
-   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-   xmlns:svg="http://www.w3.org/2000/svg"
-   xmlns="http://www.w3.org/2000/svg"
-   xmlns:xlink="http://www.w3.org/1999/xlink"
-   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
-   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
-   width="24"
-   height="24"
-   id="svg9434"
-   version="1.1"
-   inkscape:version="0.48.4 r9939"
-   sodipodi:docname="usb.svg">
-  <defs
-     id="defs9436">
-    <linearGradient
-       inkscape:collect="always"
-       id="linearGradient10012">
-      <stop
-         style="stop-color:#d3d7cf;stop-opacity:1"
-         offset="0"
-         id="stop10014" />
-      <stop
-         style="stop-color:#747671;stop-opacity:1"
-         offset="1"
-         id="stop10016" />
-    </linearGradient>
-    <linearGradient
-       inkscape:collect="always"
-       id="linearGradient9985">
-      <stop
-         style="stop-color:#a6a6a6;stop-opacity:1;"
-         offset="0"
-         id="stop9987" />
-      <stop
-         style="stop-color:#eeeeec;stop-opacity:1"
-         offset="1"
-         id="stop9989" />
-    </linearGradient>
-    <linearGradient
-       inkscape:collect="always"
-       id="linearGradient9977">
-      <stop
-         style="stop-color:#fafafa;stop-opacity:1;"
-         offset="0"
-         id="stop9979" />
-      <stop
-         style="stop-color:#fafafa;stop-opacity:0;"
-         offset="1"
-         id="stop9981" />
-    </linearGradient>
-    <linearGradient
-       inkscape:collect="always"
-       xlink:href="#linearGradient9401"
-       id="linearGradient9407"
-       x1="714.20172"
-       y1="-81.798248"
-       x2="714.20172"
-       y2="-64.777008"
-       gradientUnits="userSpaceOnUse"
-       gradientTransform="translate(0,1)" />
-    <linearGradient
-       inkscape:collect="always"
-       id="linearGradient9401">
-      <stop
-         style="stop-color:#2e5991;stop-opacity:1"
-         offset="0"
-         id="stop9403" />
-      <stop
-         style="stop-color:#4983c1;stop-opacity:1"
-         offset="1"
-         id="stop9405" />
-    </linearGradient>
-    <radialGradient
-       inkscape:collect="always"
-       xlink:href="#linearGradient9977"
-       id="radialGradient9983"
-       cx="12.001339"
-       cy="1035.3622"
-       fx="12.001339"
-       fy="1035.3622"
-       r="11.03125"
-       gradientTransform="matrix(3.5911562,0,0,1.7223807,-31.098681,-747.92565)"
-       gradientUnits="userSpaceOnUse" />
-    <linearGradient
-       inkscape:collect="always"
-       xlink:href="#linearGradient9985"
-       id="linearGradient9991"
-       x1="13.481804"
-       y1="1057.5219"
-       x2="13.481804"
-       y2="1028.9601"
-       gradientUnits="userSpaceOnUse" />
-    <linearGradient
-       inkscape:collect="always"
-       xlink:href="#linearGradient10012"
-       id="linearGradient10018"
-       x1="20.287706"
-       y1="1029.2219"
-       x2="20.287706"
-       y2="1052.9133"
-       gradientUnits="userSpaceOnUse" />
-  </defs>
-  <sodipodi:namedview
-     id="base"
-     pagecolor="#ffffff"
-     bordercolor="#666666"
-     borderopacity="1.0"
-     inkscape:pageopacity="1"
-     inkscape:pageshadow="2"
-     inkscape:zoom="1"
-     inkscape:cx="14.456171"
-     inkscape:cy="42.877288"
-     inkscape:document-units="px"
-     inkscape:current-layer="layer1"
-     showgrid="false"
-     inkscape:snap-nodes="false"
-     inkscape:snap-bbox="true"
-     borderlayer="true"
-     inkscape:showpageshadow="false"
-     showborder="false"
-     inkscape:window-width="1311"
-     inkscape:window-height="1189"
-     inkscape:window-x="764"
-     inkscape:window-y="173"
-     inkscape:window-maximized="0">
-    <inkscape:grid
-       type="xygrid"
-       id="grid9463"
-       empspacing="5"
-       visible="true"
-       enabled="true"
-       snapvisiblegridlinesonly="true" />
-  </sodipodi:namedview>
-  <metadata
-     id="metadata9439">
-    <rdf:RDF>
-      <cc:Work
-         rdf:about="">
-        <dc:format>image/svg+xml</dc:format>
-        <dc:type
-           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
-        <dc:title></dc:title>
-      </cc:Work>
-    </rdf:RDF>
-  </metadata>
-  <g
-     inkscape:label="Layer 1"
-     inkscape:groupmode="layer"
-     id="layer1"
-     transform="translate(0,-1028.3622)">
-    <rect
-       style="color:#000000;fill:url(#linearGradient9991);fill-opacity:1;fill-rule:nonzero;stroke:url(#linearGradient10018);stroke-width:0.99999994000000003;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
-       id="rect9973"
-       width="23.000017"
-       height="23.000017"
-       x="0.5"
-       y="1028.8622"
-       rx="2.1213202"
-       ry="2.1213202" />
-    <path
-       sodipodi:type="inkscape:offset"
-       inkscape:radius="-0.9722718"
-       inkscape:original="M 2.625 1028.875 C 1.4497886 1028.875 0.5 1029.7935 0.5 1030.9688 L 0.5 1049.75 C 0.5 1050.9252 1.4497886 1051.875 2.625 1051.875 L 21.375 1051.875 C 22.550211 1051.875 23.5 1050.9252 23.5 1049.75 L 23.5 1030.9688 C 23.5 1029.7935 22.550211 1028.875 21.375 1028.875 L 2.625 1028.875 z "
-       xlink:href="#rect9973"
-       style="color:#000000;fill:none;stroke:url(#radialGradient9983);stroke-width:0.99999994000000003;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
-       id="path9975"
-       inkscape:href="#rect9973"
-       d="m 2.625,1029.8438 c -0.6686179,0 -1.15625,0.4735 -1.15625,1.125 l 0,18.7812 c 0,0.6513 0.5048954,1.1562 1.15625,1.1562 l 18.75,0 c 0.651354,0 1.15625,-0.5049 1.15625,-1.1562 l 0,-18.7812 c 0,-0.6515 -0.487633,-1.125 -1.15625,-1.125 l -18.75,0 z" />
-    <g
-       transform="translate(-703,1112.3622)"
-       style="display:inline;enable-background:new"
-       id="g9411">
-      <path
-         d="m 715,-83 -4,5 3,0 0,7.5625 -1.3125,-1.3125 C 712.86766,-72.1354 713,-72.54648 713,-73 c 0,-1.65685 -1.34315,-3 -3,-3 -1.65685,0 -3,1.34315 -3,3 0,1.65685 1.34315,3 3,3 0.45352,0 0.8646,-0.13234 1.25,-0.3125 l 2.625,2.4375 0.125,0.09375 c -1.15835,0.41551 -2,1.51118 -2,2.8125 0,1.65685 1.34315,3 3,3 1.65685,0 3,-1.34315 3,-3 0,-1.30132 -0.84165,-2.39699 -2,-2.8125 l 0,-2.78125 4.4375,-4.4375 2.5625,0 0,-4 -4,0 0,1 0,1.5625 -3,3 0,-4.5625 3,0 -4,-5 z"
-         inkscape:href="#path9368"
-         id="path9399"
-         style="font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:normal;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;baseline-shift:baseline;color:#000000;fill:#ffffff;fill-opacity:0.82488477;stroke:none;stroke-width:2;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:Sans;-inkscape-font-specification:Sans"
-         xlink:href="#path9368"
-         inkscape:original="M 715 -83 L 711 -78 L 714 -78 L 714 -70.4375 L 712.6875 -71.75 C 712.86766 -72.1354 713 -72.54648 713 -73 C 713 -74.65685 711.65685 -76 710 -76 C 708.34315 -76 707 -74.65685 707 -73 C 707 -71.34315 708.34315 -70 710 -70 C 710.45352 -70 710.8646 -70.13234 711.25 -70.3125 L 713.875 -67.875 L 714 -67.78125 C 712.84165 -67.36574 712 -66.27007 712 -64.96875 C 712 -63.3119 713.34315 -61.96875 715 -61.96875 C 716.65685 -61.96875 718 -63.3119 718 -64.96875 C 718 -66.27007 717.15835 -67.36574 716 -67.78125 L 716 -70.5625 L 720.4375 -75 L 723 -75 L 723 -79 L 719 -79 L 719 -78 L 719 -76.4375 L 716 -73.4375 L 716 -78 L 719 -78 L 715 -83 z "
-         inkscape:radius="0"
-         sodipodi:type="inkscape:offset"
-         transform="translate(0,0.97227174)" />
-      <path
-         sodipodi:nodetypes="cccccsssscccsssccccccccccc"
-         inkscape:connector-curvature="0"
-         id="path9368"
-         d="m 715,-83 -4,5 3,0 0,7.5625 -1.3125,-1.3125 C 712.86766,-72.1354 713,-72.54648 713,-73 c 0,-1.65685 -1.34315,-3 -3,-3 -1.65685,0 -3,1.34315 -3,3 0,1.65685 1.34315,3 3,3 0.45352,0 0.8646,-0.13234 1.25,-0.3125 l 2.61742,2.440641 0.13258,0.08709 c -1.15835,0.41551 -2,1.51118 -2,2.8125 0,1.65685 1.34315,3 3,3 1.65685,0 3,-1.34315 3,-3 0,-1.30132 -0.84165,-2.39699 -2,-2.8125 l 0,-2.777728 4.4375,-4.4375 2.5625,0 0,-4 -4,0 0,2.5625 -3,3 0,-4.5625 3,0 z"
-         style="font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:normal;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;baseline-shift:baseline;color:#000000;fill:url(#linearGradient9407);fill-opacity:1;stroke:none;stroke-width:2;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:Sans;-inkscape-font-specification:Sans" />
-      <rect
-         y="-84"
-         x="703"
-         height="24"
-         width="24"
-         id="rect9409"
-         style="color:#000000;fill:none;stroke:none;stroke-width:2;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
-    </g>
-  </g>
-</svg>
diff --git a/src/resources/ui/virt-viewer.ui b/src/resources/ui/virt-viewer.ui
index 42cd849..c211440 100644
--- a/src/resources/ui/virt-viewer.ui
+++ b/src/resources/ui/virt-viewer.ui
@@ -222,4 +222,66 @@
       </object>
     </child>
   </object>
+  <object class="GtkHeaderBar" id="fullscreen-headerbar">
+    <property name="visible">True</property>
+    <property name="show-close-button">True</property>
+    <child>
+      <object class="GtkButton" id="fullscreen-usb-devices">
+        <property name="visible">False</property>
+        <property name="tooltip-text">USB device selection</property>
+        <style>
+          <class name="image-button"/>
+        </style>
+        <child>
+          <object class="GtkImage" id="fullscreen-usb-devices-icon">
+            <property name="visible">True</property>
+            <property name="icon-name">media-removable-symbolic</property>
+            <property name="icon-size">1</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="pack-type">end</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkMenuButton" id="fullscreen-send-keys">
+        <property name="visible">True</property>
+        <property name="use-popover">True</property>
+        <property name="tooltip-text">Send key combination</property>
+        <style>
+          <class name="image-button"/>
+        </style>
+        <child>
+          <object class="GtkImage" id="fullscreen-send-keys-icon">
+            <property name="visible">True</property>
+            <property name="icon-name">input-keyboard-symbolic</property>
+            <property name="icon-size">1</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="pack-type">end</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButton" id="leave-fullscreen">
+        <property name="visible">True</property>
+        <property name="tooltip-text">Leave fullscreen</property>
+        <style>
+          <class name="image-button"/>
+        </style>
+        <child>
+          <object class="GtkImage" id="leave-fullscreen-image">
+            <property name="visible">True</property>
+            <property name="icon-name">view-restore-symbolic</property>
+            <property name="icon-size">1</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="pack-type">end</property>
+      </packing>
+    </child>
+  </object>
 </interface>
diff --git a/src/resources/virt-viewer.gresource.xml b/src/resources/virt-viewer.gresource.xml
index f4fbab9..7bd66f9 100644
--- a/src/resources/virt-viewer.gresource.xml
+++ b/src/resources/virt-viewer.gresource.xml
@@ -14,7 +14,6 @@
     <file alias="icons/16x16/virt-viewer.png">../../icons/16x16/virt-viewer.png</file>
     <file alias="icons/22x22/virt-viewer.png">../../icons/22x22/virt-viewer.png</file>
     <file alias="icons/24x24/virt-viewer.png">../../icons/24x24/virt-viewer.png</file>
-    <file alias="icons/24x24/virt-viewer-usb.png">../../icons/24x24/virt-viewer-usb.png</file>
     <file alias="icons/32x32/virt-viewer.png">../../icons/32x32/virt-viewer.png</file>
     <file alias="icons/48x48/virt-viewer.png">../../icons/48x48/virt-viewer.png</file>
     <file alias="icons/256x256/virt-viewer.png">../../icons/256x256/virt-viewer.png</file>
diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 580bef0..fa8b008 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -2375,7 +2375,7 @@ window_update_menu_displays_cb(gpointer value,
     GtkMenuButton *button = virt_viewer_window_get_menu_button_displays(VIRT_VIEWER_WINDOW(value));
 
     sensitive = (keys != NULL);
-    virt_viewer_window_set_menu_displays_sensitive(VIRT_VIEWER_WINDOW(value), sensitive);
+    virt_viewer_window_set_headerbar_displays_sensitive(VIRT_VIEWER_WINDOW(value), sensitive);
 
     tmp = keys;
     while (tmp) {
diff --git a/src/virt-viewer-timed-revealer.c b/src/virt-viewer-timed-revealer.c
index 3c48ab5..fbb8583 100644
--- a/src/virt-viewer-timed-revealer.c
+++ b/src/virt-viewer-timed-revealer.c
@@ -178,7 +178,7 @@ virt_viewer_timed_revealer_new(GtkWidget *toolbar)
      */
 
     gtk_container_add(GTK_CONTAINER(self), priv->revealer);
-    gtk_widget_set_halign(GTK_WIDGET(self), GTK_ALIGN_CENTER);
+    gtk_widget_set_halign(GTK_WIDGET(self), GTK_ALIGN_FILL);
     gtk_widget_set_valign(GTK_WIDGET(self), GTK_ALIGN_START);
     gtk_widget_show_all(GTK_WIDGET(self));
 
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index c1278ca..60ab088 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -56,11 +56,10 @@ void virt_viewer_window_menu_send(GtkWidget *menu, VirtViewerWindow *self);
 static void virt_viewer_window_enable_modifiers(VirtViewerWindow *self);
 static void virt_viewer_window_disable_modifiers(VirtViewerWindow *self);
 static void virt_viewer_window_queue_resize(VirtViewerWindow *self);
-static void virt_viewer_window_toolbar_setup(VirtViewerWindow *self);
+static void virt_viewer_window_fullscreen_headerbar_setup(VirtViewerWindow *self);
 static void virt_viewer_window_menu_view_fullscreen(VirtViewerWindow *self);
 static void usb_device_selection_activated(GSimpleAction *action, GVariant *parameter, gpointer window);
 
-static GtkMenu* virt_viewer_window_get_keycombo_menu(VirtViewerWindow *self);
 static gint virt_viewer_window_get_minimal_zoom_level(VirtViewerWindow *self);
 
 
@@ -82,10 +81,9 @@ struct _VirtViewerWindowPrivate {
 
     GtkBuilder *builder;
     GtkWidget *window;
-    GtkWidget *toolbar;
     GtkWidget *header;
+    GtkWidget *fullscreen_headerbar;
     GtkWidget *toolbar_usb_device_selection;
-    GtkWidget *toolbar_send_key;
     GtkAccelGroup *accel_group;
     VirtViewerNotebook *notebook;
     VirtViewerDisplay *display;
@@ -192,7 +190,7 @@ virt_viewer_window_dispose (GObject *object)
     priv->subtitle = NULL;
 
     g_value_unset(&priv->accel_setting);
-    priv->toolbar = NULL;
+    priv->fullscreen_headerbar = NULL;
 
     G_OBJECT_CLASS (virt_viewer_window_parent_class)->dispose (object);
 }
@@ -248,14 +246,6 @@ virt_viewer_window_class_init (VirtViewerWindowClass *klass)
                                                         G_PARAM_STATIC_STRINGS));
 }
 
-static gboolean
-can_activate_cb (GtkWidget *widget G_GNUC_UNUSED,
-                 guint signal_id G_GNUC_UNUSED,
-                 VirtViewerWindow *self G_GNUC_UNUSED)
-{
-    return TRUE;
-}
-
 static void
 fullscreen_activated(GSimpleAction *action G_GNUC_UNUSED,
                      GVariant *parameter G_GNUC_UNUSED,
@@ -692,7 +682,7 @@ virt_viewer_window_init (VirtViewerWindow *self)
     priv->accel_group = GTK_ACCEL_GROUP(gtk_builder_get_object(priv->builder, "accelgroup"));
 
     vbox = GTK_WIDGET(gtk_builder_get_object(priv->builder, "viewer-box"));
-    virt_viewer_window_toolbar_setup(self);
+    virt_viewer_window_fullscreen_headerbar_setup(self);
 
     gtk_box_pack_end(GTK_BOX(vbox), GTK_WIDGET(priv->notebook), TRUE, TRUE, 0);
 
@@ -822,7 +812,7 @@ virt_viewer_window_leave_fullscreen(VirtViewerWindow *self)
         virt_viewer_display_set_fullscreen(priv->display, FALSE);
     }
     virt_viewer_timed_revealer_force_reveal(priv->revealer, FALSE);
-    gtk_widget_hide(priv->toolbar);
+    gtk_widget_hide(priv->fullscreen_headerbar);
     gtk_widget_set_size_request(priv->window, -1, -1);
     gtk_window_unfullscreen(GTK_WINDOW(priv->window));
 
@@ -853,7 +843,7 @@ virt_viewer_window_enter_fullscreen(VirtViewerWindow *self, gint monitor)
         return;
     }
 
-    gtk_widget_show(priv->toolbar);
+    gtk_widget_show(priv->fullscreen_headerbar);
     virt_viewer_timed_revealer_force_reveal(priv->revealer, TRUE);
 
     if (priv->display) {
@@ -865,174 +855,6 @@ virt_viewer_window_enter_fullscreen(VirtViewerWindow *self, gint monitor)
     gtk_window_fullscreen(GTK_WINDOW(priv->window));
 }
 
-#define MAX_KEY_COMBO 4
-struct keyComboDef {
-    guint keys[MAX_KEY_COMBO];
-    const char *label;
-    const gchar* accel_path;
-};
-
-struct gkeyComboDef {
-    const char *label;
-    const gchar* action;
-};
-
-static const struct keyComboDef keyCombos[] = {
-    { { GDK_KEY_Control_L, GDK_KEY_Alt_L, GDK_KEY_Delete, GDK_KEY_VoidSymbol }, N_("Ctrl+Alt+_Del"), "<virt-viewer>/send/secure-attention"},
-    { { GDK_KEY_Control_L, GDK_KEY_Alt_L, GDK_KEY_BackSpace, GDK_KEY_VoidSymbol }, N_("Ctrl+Alt+_Backspace"), NULL},
-    { { GDK_KEY_VoidSymbol }, "" , NULL},
-    { { GDK_KEY_Control_L, GDK_KEY_Alt_L, GDK_KEY_F1, GDK_KEY_VoidSymbol }, N_("Ctrl+Alt+F_1"), NULL},
-    { { GDK_KEY_Control_L, GDK_KEY_Alt_L, GDK_KEY_F2, GDK_KEY_VoidSymbol }, N_("Ctrl+Alt+F_2"), NULL},
-    { { GDK_KEY_Control_L, GDK_KEY_Alt_L, GDK_KEY_F3, GDK_KEY_VoidSymbol }, N_("Ctrl+Alt+F_3"), NULL},
-    { { GDK_KEY_Control_L, GDK_KEY_Alt_L, GDK_KEY_F4, GDK_KEY_VoidSymbol }, N_("Ctrl+Alt+F_4"), NULL},
-    { { GDK_KEY_Control_L, GDK_KEY_Alt_L, GDK_KEY_F5, GDK_KEY_VoidSymbol }, N_("Ctrl+Alt+F_5"), NULL},
-    { { GDK_KEY_Control_L, GDK_KEY_Alt_L, GDK_KEY_F6, GDK_KEY_VoidSymbol }, N_("Ctrl+Alt+F_6"), NULL},
-    { { GDK_KEY_Control_L, GDK_KEY_Alt_L, GDK_KEY_F7, GDK_KEY_VoidSymbol }, N_("Ctrl+Alt+F_7"), NULL},
-    { { GDK_KEY_Control_L, GDK_KEY_Alt_L, GDK_KEY_F8, GDK_KEY_VoidSymbol }, N_("Ctrl+Alt+F_8"), NULL},
-    { { GDK_KEY_Control_L, GDK_KEY_Alt_L, GDK_KEY_F9, GDK_KEY_VoidSymbol }, N_("Ctrl+Alt+F_9"), NULL},
-    { { GDK_KEY_Control_L, GDK_KEY_Alt_L, GDK_KEY_F10, GDK_KEY_VoidSymbol }, N_("Ctrl+Alt+F1_0"), NULL},
-    { { GDK_KEY_Control_L, GDK_KEY_Alt_L, GDK_KEY_F11, GDK_KEY_VoidSymbol }, N_("Ctrl+Alt+F11"), NULL},
-    { { GDK_KEY_Control_L, GDK_KEY_Alt_L, GDK_KEY_F12, GDK_KEY_VoidSymbol }, N_("Ctrl+Alt+F12"), NULL},
-    { { GDK_KEY_VoidSymbol }, "" , NULL},
-    { { GDK_KEY_Print, GDK_KEY_VoidSymbol }, "_PrintScreen", NULL},
-};
-
-static guint
-get_nkeys(const guint *keys)
-{
-    guint i;
-
-    for (i = 0; keys[i] != GDK_KEY_VoidSymbol; )
-        i++;
-
-    return i;
-}
-
-G_MODULE_EXPORT void
-virt_viewer_window_menu_send(GtkWidget *menu,
-                             VirtViewerWindow *self)
-{
-    VirtViewerWindowPrivate *priv = self->priv;
-
-    g_return_if_fail(priv->display != NULL);
-    guint *keys = g_object_get_data(G_OBJECT(menu), "vv-keys");
-    g_return_if_fail(keys != NULL);
-
-    virt_viewer_display_send_keys(VIRT_VIEWER_DISPLAY(priv->display),
-                                  keys, get_nkeys(keys));
-}
-
-static void
-virt_viewer_menu_add_combo(VirtViewerWindow *self, GtkMenu *menu,
-                           const guint *keys, const gchar *label, const gchar* accel_path)
-{
-    GtkWidget *item;
-
-    if (keys == NULL || keys[0] == GDK_KEY_VoidSymbol) {
-        item = gtk_separator_menu_item_new();
-    } else {
-        item = gtk_menu_item_new_with_mnemonic(label);
-        if (accel_path) {
-            gtk_menu_item_set_accel_path(GTK_MENU_ITEM(item), accel_path);
-            /* make accel work in fullscreen */
-            g_signal_connect(item, "can-activate-accel", G_CALLBACK(can_activate_cb), self);
-        }
-        guint *ckeys = g_memdup(keys, (get_nkeys(keys) + 1) * sizeof(guint));
-        g_object_set_data_full(G_OBJECT(item), "vv-keys", ckeys, g_free);
-        g_signal_connect(item, "activate", G_CALLBACK(virt_viewer_window_menu_send), self);
-    }
-
-    gtk_container_add(GTK_CONTAINER(menu), item);
-}
-
-static guint*
-accel_key_to_keys(const GtkAccelKey *key)
-{
-    guint i;
-    guint *val, *keys;
-    const struct {
-        const guint mask;
-        const guint key;
-    } modifiers[] = {
-        {GDK_SHIFT_MASK, GDK_KEY_Shift_L},
-        {GDK_CONTROL_MASK, GDK_KEY_Control_L},
-        {GDK_MOD1_MASK, GDK_KEY_Alt_L},
-    };
-
-    g_warn_if_fail((key->accel_mods &
-                    ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) == 0);
-
-    keys = val = g_new(guint, 5); /* up to 3 modifiers, key and the stop symbol */
-    /* first, send the modifiers */
-    for (i = 0; i < G_N_ELEMENTS(modifiers); i++) {
-        if (key->accel_mods & modifiers[i].mask)
-            *val++ = modifiers[i].key;
-    }
-
-    /* only after, the non-modifier key (ctrl-t, not t-ctrl) */
-    *val++ = key->accel_key;
-    /* stop symbol */
-    *val = GDK_KEY_VoidSymbol;
-
-    return keys;
-}
-
-struct accelCbData
-{
-    VirtViewerWindow *self;
-    GtkMenu *menu;
-};
-
-static void
-accel_map_item_cb(gpointer data,
-                  const gchar *accel_path,
-                  guint accel_key,
-                  GdkModifierType accel_mods,
-                  gboolean changed G_GNUC_UNUSED)
-{
-    struct accelCbData *d = data;
-    GtkAccelKey key = {
-        .accel_key = accel_key,
-        .accel_mods = accel_mods
-    };
-
-    if (!g_str_has_prefix(accel_path, "<virt-viewer>"))
-        return;
-    if (accel_key == GDK_KEY_VoidSymbol || accel_key == 0)
-        return;
-
-    guint *keys = accel_key_to_keys(&key);
-    gchar *label = gtk_accelerator_get_label(accel_key, accel_mods);
-    virt_viewer_menu_add_combo(d->self, d->menu, keys, label, NULL);
-    g_free(label);
-    g_free(keys);
-}
-
-static GtkMenu*
-virt_viewer_window_get_keycombo_menu(VirtViewerWindow *self)
-{
-    gint i;
-    VirtViewerWindowPrivate *priv = self->priv;
-    GtkMenu *menu = GTK_MENU(gtk_menu_new());
-    gtk_menu_set_accel_group(menu, priv->accel_group);
-
-    for (i = 0 ; i < G_N_ELEMENTS(keyCombos); i++) {
-        virt_viewer_menu_add_combo(self, menu, keyCombos[i].keys, keyCombos[i].label, keyCombos[i].accel_path);
-    }
-
-    if (virt_viewer_app_get_enable_accel(priv->app)) {
-        struct accelCbData d = {
-            .self = self,
-            .menu = menu
-        };
-
-        gtk_accel_map_foreach(&d, accel_map_item_cb);
-    }
-
-    gtk_widget_show_all(GTK_WIDGET(menu));
-    return menu;
-}
-
 void
 virt_viewer_window_disable_modifiers(VirtViewerWindow *self)
 {
@@ -1109,15 +931,6 @@ virt_viewer_window_delete(GtkWidget *src G_GNUC_UNUSED,
     return TRUE;
 }
 
-
-static void
-virt_viewer_window_menu_file_quit(GtkWidget *src G_GNUC_UNUSED,
-                                  VirtViewerWindow *self)
-{
-    virt_viewer_app_maybe_quit(self->priv->app, self);
-}
-
-
 static void
 virt_viewer_window_set_fullscreen(VirtViewerWindow *self,
                                   gboolean fullscreen)
@@ -1135,39 +948,12 @@ virt_viewer_window_set_fullscreen(VirtViewerWindow *self,
 }
 
 static void
-virt_viewer_window_toolbar_leave_fullscreen(GtkWidget *button G_GNUC_UNUSED,
+virt_viewer_window_headerbar_leave_fullscreen(GtkWidget *button G_GNUC_UNUSED,
                                             VirtViewerWindow *self)
 {
     virt_viewer_window_set_fullscreen(self, FALSE);
 }
 
-static void keycombo_menu_location(GtkMenu *menu G_GNUC_UNUSED, gint *x, gint *y,
-                                   gboolean *push_in, gpointer user_data)
-{
-    VirtViewerWindow *self = user_data;
-    GtkAllocation allocation;
-    GtkWidget *toplevel = gtk_widget_get_toplevel(self->priv->toolbar_send_key);
-
-    *push_in = TRUE;
-    gdk_window_get_origin(gtk_widget_get_window(toplevel), x, y);
-    gtk_widget_translate_coordinates(self->priv->toolbar_send_key, toplevel,
-                                     *x, *y, x, y);
-    gtk_widget_get_allocation(self->priv->toolbar_send_key, &allocation);
-    *y += allocation.height;
-}
-
-static void
-virt_viewer_window_toolbar_send_key(GtkWidget *button G_GNUC_UNUSED,
-                                    VirtViewerWindow *self)
-{
-    GtkMenu *menu = virt_viewer_window_get_keycombo_menu(self);
-    gtk_menu_attach_to_widget(menu, self->priv->window, NULL);
-    g_object_ref_sink(menu);
-    gtk_menu_popup(menu, NULL, NULL, keycombo_menu_location, self,
-                   0, gtk_get_current_event_time());
-    g_object_unref(menu);
-}
-
 static void
 virt_viewer_window_menu_view_fullscreen(VirtViewerWindow *self)
 {
@@ -1184,56 +970,39 @@ virt_viewer_window_guest_details_response(GtkDialog *dialog,
 }
 
 static void
-virt_viewer_window_toolbar_setup(VirtViewerWindow *self)
+virt_viewer_window_headerbar_usb_device_selection(GtkWidget *menu G_GNUC_UNUSED,
+                                                  VirtViewerWindow *self)
+{
+    virt_viewer_session_usb_device_selection(virt_viewer_app_get_session(self->priv->app),
+                                             GTK_WINDOW(self->priv->window));
+}
+
+static void
+virt_viewer_window_fullscreen_headerbar_setup(VirtViewerWindow *self)
 {
-    GtkWidget *button;
     GtkWidget *overlay;
+    GtkWidget *leave_fullscreen_button;
+    GtkWidget *usb_devices_button;
+    GtkWidget *send_keys_button;
+    GMenuModel *send_keys_menu;
+
     VirtViewerWindowPrivate *priv = self->priv;
 
-    priv->toolbar = gtk_toolbar_new();
-    gtk_toolbar_set_show_arrow(GTK_TOOLBAR(priv->toolbar), FALSE);
-    gtk_widget_set_no_show_all(priv->toolbar, TRUE);
-    gtk_toolbar_set_style(GTK_TOOLBAR(priv->toolbar), GTK_TOOLBAR_BOTH_HORIZ);
-
-    /* Close connection */
-    button = GTK_WIDGET(gtk_tool_button_new(NULL, NULL));
-    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(button), "window-close");
-    gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(button), _("Disconnect"));
-    gtk_widget_show(button);
-    gtk_toolbar_insert(GTK_TOOLBAR(priv->toolbar), GTK_TOOL_ITEM (button), 0);
-    g_signal_connect(button, "clicked", G_CALLBACK(virt_viewer_window_menu_file_quit), self);
-
-    /* USB Device selection */
-    button = gtk_image_new_from_resource(VIRT_VIEWER_RESOURCE_PREFIX"/icons/24x24/virt-viewer-usb.png");
-    button = GTK_WIDGET(gtk_tool_button_new(button, NULL));
-    gtk_tool_button_set_label(GTK_TOOL_BUTTON(button), _("USB device selection"));
-    gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(button), _("USB device selection"));
-    gtk_toolbar_insert(GTK_TOOLBAR(priv->toolbar), GTK_TOOL_ITEM(button), 0);
-    g_signal_connect(button, "clicked", G_CALLBACK(usb_device_selection_activated), self);
-    priv->toolbar_usb_device_selection = button;
-    gtk_widget_show_all(button);
-
-    /* Send key */
-    button = GTK_WIDGET(gtk_tool_button_new(NULL, NULL));
-    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(button), "preferences-desktop-keyboard-shortcuts");
-    gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(button), _("Send key combination"));
-    gtk_widget_show(button);
-    gtk_toolbar_insert(GTK_TOOLBAR(priv->toolbar), GTK_TOOL_ITEM(button), 0);
-    g_signal_connect(button, "clicked", G_CALLBACK(virt_viewer_window_toolbar_send_key), self);
-    gtk_widget_set_sensitive(button, FALSE);
-    priv->toolbar_send_key = button;
-
-    /* Leave fullscreen */
-    button = GTK_WIDGET(gtk_tool_button_new(NULL, NULL));
-    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(button), "view-restore");
-    gtk_tool_button_set_label(GTK_TOOL_BUTTON(button), _("Leave fullscreen"));
-    gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(button), _("Leave fullscreen"));
-    gtk_tool_item_set_is_important(GTK_TOOL_ITEM(button), TRUE);
-    gtk_widget_show(button);
-    gtk_toolbar_insert(GTK_TOOLBAR(priv->toolbar), GTK_TOOL_ITEM(button), 0);
-    g_signal_connect(button, "clicked", G_CALLBACK(virt_viewer_window_toolbar_leave_fullscreen), self);
-
-    priv->revealer = virt_viewer_timed_revealer_new(priv->toolbar);
+    leave_fullscreen_button = GTK_WIDGET(gtk_builder_get_object(priv->builder, "leave-fullscreen"));
+    g_signal_connect(leave_fullscreen_button, "clicked",
+                      G_CALLBACK(virt_viewer_window_headerbar_leave_fullscreen), self);
+
+    send_keys_button = GTK_WIDGET(gtk_builder_get_object(priv->builder, "fullscreen-send-keys"));
+    send_keys_menu = G_MENU_MODEL (gtk_builder_get_object (priv->builder, "send-keys-menu"));
+    gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (send_keys_button), send_keys_menu);
+
+    usb_devices_button = GTK_WIDGET(gtk_builder_get_object(priv->builder, "fullscreen-usb-devices"));
+    priv->toolbar_usb_device_selection = usb_devices_button;
+    g_signal_connect(usb_devices_button, "clicked",
+                     G_CALLBACK(virt_viewer_window_headerbar_usb_device_selection), self);
+
+    priv->fullscreen_headerbar = GTK_WIDGET(gtk_builder_get_object(priv->builder, "fullscreen-headerbar"));
+    priv->revealer = virt_viewer_timed_revealer_new(priv->fullscreen_headerbar);
     overlay = GTK_WIDGET(gtk_builder_get_object(priv->builder, "viewer-overlay"));
     gtk_overlay_add_overlay(GTK_OVERLAY(overlay), GTK_WIDGET(priv->revealer));
 }
@@ -1336,17 +1105,17 @@ virt_viewer_window_update_title(VirtViewerWindow *self)
 }
 
 void
-virt_viewer_window_set_menu_displays_sensitive(VirtViewerWindow *self, gboolean sensitive)
+virt_viewer_window_set_headerbar_displays_sensitive(VirtViewerWindow *self, gboolean sensitive)
 {
     VirtViewerWindowPrivate *priv;
-    GtkWidget *menu;
+    GtkWidget *displays;
 
     g_return_if_fail(VIRT_VIEWER_IS_WINDOW(self));
 
     priv = self->priv;
 
-    menu = GTK_WIDGET(gtk_builder_get_object(priv->builder, "displays"));
-    gtk_widget_set_sensitive(menu, sensitive);
+    displays = GTK_WIDGET(gtk_builder_get_object(priv->builder, "displays"));
+    gtk_widget_set_sensitive(displays, sensitive);
 }
 
 void
diff --git a/src/virt-viewer-window.h b/src/virt-viewer-window.h
index f578637..17cc6cf 100644
--- a/src/virt-viewer-window.h
+++ b/src/virt-viewer-window.h
@@ -68,7 +68,7 @@ GtkWindow* virt_viewer_window_get_window (VirtViewerWindow* window);
 VirtViewerNotebook* virt_viewer_window_get_notebook (VirtViewerWindow* window);
 void virt_viewer_window_set_display(VirtViewerWindow *self, VirtViewerDisplay *display);
 VirtViewerDisplay* virt_viewer_window_get_display(VirtViewerWindow *self);
-void virt_viewer_window_set_menu_displays_sensitive(VirtViewerWindow *self, gboolean sensitive);
+void virt_viewer_window_set_headerbar_displays_sensitive(VirtViewerWindow *self, gboolean sensitive);
 void virt_viewer_window_set_usb_options_sensitive(VirtViewerWindow *self, gboolean sensitive);
 void virt_viewer_window_set_menus_sensitive(VirtViewerWindow *self, gboolean sensitive);
 void virt_viewer_window_update_title(VirtViewerWindow *self);
-- 
2.9.3




More information about the virt-tools-list mailing list