[gnote] Use client side window decorations only on Gnome



commit c7e73b8a178dbecdf6a31087b36cbae284fe107d
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sat Apr 25 18:12:50 2015 +0300

    Use client side window decorations only on Gnome
    
    Fixes bug 748121.

 src/mainwindow.cpp    |   21 ++++++++++++++++++++-
 src/mainwindow.hpp    |    5 ++++-
 src/recentchanges.cpp |   47 +++++++++++++++++++++++++++++++++++------------
 src/recentchanges.hpp |    5 ++---
 4 files changed, 61 insertions(+), 17 deletions(-)
---
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 0b8d805..9dd0d13 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2013 Aurimas Cernius
+ * Copyright (C) 2013,2015 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -18,12 +18,17 @@
  */
 
 
+#include <cstring>
+
 #include "ignote.hpp"
 #include "mainwindow.hpp"
 #include "notewindow.hpp"
 
 namespace gnote {
 
+int MainWindow::s_use_client_side_decorations = -1;
+
+
 MainWindow *MainWindow::get_owning(Gtk::Widget & widget)
 {
   Gtk::Container *container = widget.get_parent();
@@ -96,6 +101,20 @@ MainWindow *MainWindow::present_default(const Note::Ptr & note)
   return win;
 }
 
+bool MainWindow::use_client_side_decorations()
+{
+  if (s_use_client_side_decorations < 0) {
+    if(std::strcmp(std::getenv("DESKTOP_SESSION"), "gnome") == 0) {
+      s_use_client_side_decorations = 1;
+    }
+    else {
+      s_use_client_side_decorations = 0;
+    }
+  }
+
+  return s_use_client_side_decorations;
+}
+
 
 MainWindow::MainWindow(const std::string & title)
   : utils::ForcedPresentWindow(title)
diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp
index b77807f..8fd8c7d 100644
--- a/src/mainwindow.hpp
+++ b/src/mainwindow.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2013 Aurimas Cernius
+ * Copyright (C) 2013,2015 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -38,6 +38,7 @@ public:
   static MainWindow *present_active(const Note::Ptr & note);
   static MainWindow *present_in_new_window(const Note::Ptr & note, bool close_on_esacpe);
   static MainWindow *present_default(const Note::Ptr & note);
+  static bool use_client_side_decorations();
 
   explicit MainWindow(const std::string & title);
 
@@ -58,6 +59,8 @@ public:
 protected:
   virtual void present_note(const Note::Ptr & note) = 0;
 private:
+  static int s_use_client_side_decorations;
+
   bool m_close_on_esc;
 };
 
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index 1e84af6..f087e2e 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -26,6 +26,7 @@
 #include <boost/bind.hpp>
 #include <glibmm/i18n.h>
 #include <gtkmm/alignment.h>
+#include <gtkmm/headerbar.h>
 #include <gtkmm/image.h>
 #include <gtkmm/separatormenuitem.h>
 #include <gtkmm/stock.h>
@@ -72,11 +73,17 @@ namespace gnote {
       .connect(sigc::mem_fun(*this, &NoteRecentChanges::on_notes_widget_key_press));
 
     make_header_bar();
-    set_titlebar(m_header_bar);
     make_search_box();
     m_content_vbox.set_orientation(Gtk::ORIENTATION_VERTICAL);
-    m_content_vbox.attach(m_search_box, 0, 0, 1, 1);
-    m_content_vbox.attach(m_embed_box, 0, 1, 1, 1);
+    int content_y_attach = 0;
+    if(use_client_side_decorations()) {
+      set_titlebar(*static_cast<Gtk::HeaderBar*>(m_header_bar));
+    }
+    else {
+      m_content_vbox.attach(*m_header_bar, 0, content_y_attach++, 1, 1);
+    }
+    m_content_vbox.attach(m_search_box, 0, content_y_attach++, 1, 1);
+    m_content_vbox.attach(m_embed_box, 0, content_y_attach++, 1, 1);
     m_embed_box.set_hexpand(true);
     m_embed_box.set_vexpand(true);
     m_embed_box.show();
@@ -114,8 +121,6 @@ namespace gnote {
 
   void NoteRecentChanges::make_header_bar()
   {
-    m_header_bar.set_show_close_button(true);
-
     Gtk::Grid *left_box = manage(new Gtk::Grid);
     left_box->get_style_context()->add_class(GTK_STYLE_CLASS_RAISED);
     left_box->set_orientation(Gtk::ORIENTATION_HORIZONTAL);
@@ -169,10 +174,28 @@ namespace gnote {
     right_box->attach(*m_window_actions_button, 1, 0, 1, 1);
     right_box->show();
 
-    m_header_bar.pack_start(*left_box);
-    m_header_bar.pack_end(*right_box);
-    m_header_bar.pack_end(m_embedded_toolbar);
-    m_header_bar.show();
+    if(use_client_side_decorations()) {
+      Gtk::HeaderBar *header_bar = manage(new Gtk::HeaderBar);
+      header_bar->set_show_close_button(true);
+      header_bar->pack_start(*left_box);
+      header_bar->pack_end(*right_box);
+      header_bar->pack_end(m_embedded_toolbar);
+      m_header_bar = header_bar;
+    }
+    else {
+      Gtk::Grid *header_bar = manage(new Gtk::Grid);
+      header_bar->set_margin_left(5);
+      header_bar->set_margin_right(5);
+      header_bar->set_margin_top(5);
+      header_bar->set_margin_bottom(5);
+      header_bar->attach(*left_box, 0, 0, 1, 1);
+      left_box->set_hexpand(true);
+      header_bar->attach(m_embedded_toolbar, 2, 0, 1, 1);
+      header_bar->attach(*right_box, 3, 0, 1, 1);
+      m_header_bar = header_bar;
+    }
+
+    m_header_bar->show();
   }
 
   void NoteRecentChanges::make_search_box()
@@ -475,10 +498,10 @@ namespace gnote {
  
       update_toolbar(widget);
       if(&widget == &m_search_notes_widget) {
-        m_header_bar.set_title(_("Gnote"));
+        set_title(_("Gnote"));
       }
       else {
-        m_header_bar.set_title(widget.get_name());
+        set_title(widget.get_name());
         m_current_embedded_name_slot = widget.signal_name_changed
           .connect(sigc::mem_fun(*this, &NoteRecentChanges::on_embedded_name_changed));
       }
@@ -690,7 +713,7 @@ namespace gnote {
 
   void NoteRecentChanges::on_embedded_name_changed(const std::string & name)
   {
-    m_header_bar.set_title(name);
+    set_title(name);
   }
 
   void NoteRecentChanges::on_main_window_actions_changed(Gtk::Menu **menu)
diff --git a/src/recentchanges.hpp b/src/recentchanges.hpp
index da9772f..3153ad1 100644
--- a/src/recentchanges.hpp
+++ b/src/recentchanges.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2014 Aurimas Cernius
+ * Copyright (C) 2010-2015 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -29,7 +29,6 @@
 #include <gtkmm/alignment.h>
 #include <gtkmm/applicationwindow.h>
 #include <gtkmm/grid.h>
-#include <gtkmm/headerbar.h>
 
 #include "base/macros.hpp"
 #include "note.hpp"
@@ -93,7 +92,7 @@ private:
   bool on_notes_widget_key_press(GdkEventKey*);
 
   NoteManager        &m_note_manager;
-  Gtk::HeaderBar      m_header_bar;
+  Gtk::Widget        *m_header_bar;
   SearchNotesWidget   m_search_notes_widget;
   Gtk::Grid           m_content_vbox;
   Gtk::Alignment      m_search_box;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]