GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Sep 18, 2014 1:42 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Tutorial for GTK Window without title bar? is there one?
PostPosted: Thu Nov 03, 2011 10:18 am 
Offline
Familiar Face

Joined: Thu Aug 18, 2011 8:26 am
Posts: 16
I am trying to expand my knowledge of GTK, from basics right through to advanced tasks.

For my next little project I would like to create a custom window, where I have no titlebar, and implement my own, so that I may do things like putting widgets in the titlebar, like chrome and firefox.

I really like that style of user interface as I think it makes good use of the wasted headspace in the titlebar.

I am aware that I would also have to recode the window behaviour, like resizing, dragging, closing, maximising, minimising etc.

Is there a tutorial available online for this? or does anyone have an example they can show me that I can learn from?

If I manage to build it, I will make it available for people to use.

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Tutorial for GTK Window without title bar? is there one?
PostPosted: Thu Nov 03, 2011 7:09 pm 
Offline
GTK+ Guru

Joined: Sun Apr 06, 2008 6:43 pm
Posts: 286
Location: Fortress of solitude
Easy, just pure layout managments and the decorated state of the dialog:
Code:
#!/usr/bin/perl -w

use utf8;
use strict;
use Gtk2;
use Glib qw/ TRUE FALSE /;

sub splash
{
   my ($sender, $toplevel) = @_;
   my $dlg = Gtk2::Dialog->new('You wont see me', $toplevel, ['destroy-with-parent']);
   $dlg->set_has_separator (FALSE);
   $dlg->set_decorated (FALSE);
   $dlg->set_size_request (600, 500);
   my $layout = $dlg->get_content_area; # inner layout
   # place a horizantal widget container
   my $hbox1 = Gtk2::HBox->new (FALSE, 0);
   # system menu
   my $sysmenu = Gtk2::Button->new_from_stock ('gtk-open'); #system menu
   # title bar
   my $a1 = Gtk2::Alignment->new (0.0, 0.5, 0.0, 0.0);
   my $titlebar = Gtk2::Label->new ('My browser title');
   # place a button holder (also a horizontal widget container)
   my $hbox2 = Gtk2::HBox->new (FALSE, 0);
   # button set
   my $a2 = Gtk2::Alignment->new (1.0, 0.5, 0.0, 0.0);
   my $b1 = Gtk2::Button->new_from_stock ('gtk-ok'); # minimize
   my $b2 = Gtk2::Button->new_from_stock ('gtk-cancel'); # maximize
   my $b3 = Gtk2::Button->new_from_stock ('gtk-quit'); # close
   # our inner poopy html widget
   my $browser = Gtk2::TextView->new;
   # layout
   $hbox1->pack_start ($sysmenu, FALSE, FALSE, 0);
   $a1->add ($titlebar);
   $hbox1->pack_start ($a1, TRUE, FALSE, 0);
   $hbox2->pack_start ($b1, FALSE, FALSE, 0);
   $hbox2->pack_start ($b2, FALSE, FALSE, 0);
   $hbox2->pack_start ($b3, FALSE, FALSE, 0);
   $a2->add ($hbox2);
   $hbox1->pack_start ($a2, FALSE, FALSE, 0);
   $layout->pack_start ($hbox1, FALSE, FALSE, 0);
   $layout->pack_start ($browser, TRUE, TRUE, 0);
   # signals
   $b1->signal_connect_swapped ('clicked' => sub{ shift->destroy; }, $dlg);
   $layout->show_all;
   $dlg->run;
   
}

sub Main
{
   Gtk2->init;
   my $win = Gtk2::Window->new ('toplevel');
   $win->set_position ('center');
   $win->set_border_width (10);
   $win->set_size_request (350, 150);
   # widgets
   my $layout = Gtk2::VBox->new (FALSE, 0);
   my $b1 = Gtk2::Button->new_from_stock ('gtk-ok');
   # layout
   $layout->pack_start ($b1, TRUE, FALSE, 0);
   $win->add ($layout);
   # signal connections
   $win->signal_connect ('destroy' => sub { Gtk2->main_quit; });
   $b1->signal_connect ('clicked' => \&splash, $win);
   $win->show_all;
   Gtk2->main;
   return 0;
}

exit (Main);

_________________
* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.


Top
 Profile  
 
 Post subject: Re: Tutorial for GTK Window without title bar? is there one?
PostPosted: Thu Nov 03, 2011 8:33 pm 
Offline
Familiar Face

Joined: Thu Aug 18, 2011 8:26 am
Posts: 16
Thanks joel! I hate to be awkward, but is there any way you could translate that to C++ / GTK#

I should have mentioned I have no python experience! sorry!

thanks though!


Top
 Profile  
 
 Post subject: Re: Tutorial for GTK Window without title bar? is there one?
PostPosted: Sat Dec 17, 2011 10:35 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
void Gtk::Window::set_decorated(bool setting = true)
http://developer.gnome.org/gtkmm/stable/classGtk_1_1Window.html#a67adb1d8051a38e0e5272f141bb8778c

If you set the window to not be decorated and don't have a button in the program to close the window you'll have to force it to close with the command line.
Well, I can get you one step closer anyway and in case people using C wanted to know. I don't know Gtk for C++ but I do know it for C. This is for Gtk+-3.2.0 on Ubuntu 11.04 (natty)
Code:
/*  Compile with:  gcc -Wall -o button `pkg-config --cflags --libs gtk+-3.0` button.c */

#include <gtk/gtk.h>

int main(int argc, char *argv[] )
{
  GtkWidget *window;
  GtkWidget *button;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size(GTK_WINDOW(window), 500, 300);
  gtk_window_set_decorated(GTK_WINDOW(window),FALSE);    // THIS is the line you want
  /* the next line is in case you want to disable the line above */
  g_signal_connect (GTK_WIDGET (window), "destroy",
                        G_CALLBACK (gtk_main_quit), NULL);

  button = gtk_button_new_with_label("close"); 
  gtk_widget_set_halign (GTK_WIDGET(button),GTK_ALIGN_CENTER);
  gtk_widget_set_valign (GTK_WIDGET(button),GTK_ALIGN_CENTER);
  gtk_widget_set_size_request(GTK_WIDGET(button), 100, 75);
  gtk_container_add(GTK_CONTAINER(window),button);
  g_signal_connect (GTK_WIDGET (button), "clicked",
                        G_CALLBACK (gtk_main_quit), NULL);

  gtk_widget_show_all(window);
  gtk_main();
return(0);
}


Top
 Profile  
 
 Post subject: Re: Tutorial for GTK Window without title bar? is there one?
PostPosted: Sun Dec 18, 2011 8:00 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 745
Location: UK
Just for completeness here is the same program using C++ and the gtkmm bindings.
Code:
/*  Compile with:  gcc -Wall -o button `pkg-config --cflags --libs gtkmm-3.0` button.cc */

#include <gtkmm.h>

int main(int argc, char *argv[] )
{
  Gtk::Main kit(argc, argv);

  Gtk::Window window;

  window.set_default_size(500, 300);
  window.set_decorated(false);    // THIS is the line you want

  Gtk::Button button("close");
  button.set_halign(Gtk::ALIGN_CENTER);
  button.set_valign(Gtk::ALIGN_CENTER);
  button.set_size_request(100, 75);

  window.add(button);
  button.signal_clicked().connect(sigc::ptr_fun(&Gtk::Main::quit));

  window.show_all();
  kit.run(window);

  return 0;
}

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group