Permalink
Browse files

Added support for borderless windows

  • Loading branch information...
1 parent 7df0783 commit 806df348875339e8eb848201ee7e37ec2ab56184 @wedesoft committed Aug 9, 2011
Showing with 74 additions and 37 deletions.
  1. +1 −1 Rakefile
  2. +27 −28 ext/x11window.cc
  3. +5 −5 ext/x11window.hh
  4. +4 −3 lib/hornetseye-xorg/x11display.rb
  5. +36 −0 lib/hornetseye-xorg/x11window.rb
  6. +1 −0 lib/hornetseye_xorg_ext.rb
View
@@ -7,7 +7,7 @@ require 'rake/loaders/makefile'
require 'rbconfig'
PKG_NAME = 'hornetseye-xorg'
-PKG_VERSION = '0.6.0'
+PKG_VERSION = '0.7.0'
CFG = RbConfig::CONFIG
CXX = ENV[ 'CXX' ] || 'g++'
RB_FILES = FileList[ 'lib/**/*.rb' ]
View
@@ -199,33 +199,24 @@ static const char *hornetseye_xpm[] = {
"e.^ % V.V.Q y j.V.V.U t V.V.[ M "
};
+typedef struct {
+ unsigned long flags;
+ unsigned long functions;
+ unsigned long decorations;
+ long inputMode;
+ unsigned long status;
+} Hints;
+
VALUE X11Window::cRubyClass = Qnil;
-X11Window::X11Window( X11DisplayPtr display, X11PainterPtr painter,
- int width, int height, Window parent ):
+X11Window::X11Window(X11DisplayPtr display, X11PainterPtr painter,
+ int width, int height, Window parent, bool border):
m_display(display), m_painter(painter), m_width(width), m_height(height)
{
- // state = true;
ERRORMACRO( width > 0 && height > 0, Error, ,
width << 'x' << height << " is an illegal window size." );
m_visualInfo = painter->visualInfo( display );
- /* // Request true-colour X11 visual.
- if ( !XMatchVisualInfo( display->get(),
- DefaultScreen( display->get() ),
- 24, TrueColor, &m_visualInfo) ) {
- if ( !XMatchVisualInfo( display->get(),
- DefaultScreen( display->get() ),
- 16, TrueColor, &m_visualInfo ) ) {
- if ( !XMatchVisualInfo( display->get(),
- DefaultScreen( display->get() ),
- 15, TrueColor, &m_visualInfo ) ) {
- ERRORMACRO( false, Error, ,
- "Could not get X11 visual for true-colour display." );
- };
- };
- }; */
-
// Create a color map.
m_colourMap = XCreateColormap( m_display->get(),
DefaultRootWindow( display->get() ),
@@ -257,9 +248,17 @@ X11Window::X11Window( X11DisplayPtr display, X11PainterPtr painter,
&attributes );
ERRORMACRO( m_window != 0, Error, , "Error creating X11 window." );
- wmProtocols = XInternAtom( display->get(), "WM_PROTOCOLS", False );
- wmDeleteWindow = XInternAtom( display->get(), "WM_DELETE_WINDOW", False );
- XSetWMProtocols( display->get(), m_window, &wmDeleteWindow, 1 );
+ Atom wmProperty = XInternAtom(display->get(), "_MOTIF_WM_HINTS", True);
+ Hints hints;
+ hints.flags = 2;
+ hints.decorations = border ? 1 : 0;
+ XChangeProperty(display->get(), m_window, wmProperty, wmProperty, 32,
+ PropModeReplace,(unsigned char *)&hints, 5);
+
+ m_wmProtocols = XInternAtom( display->get(), "WM_PROTOCOLS", False );
+ m_wmDeleteWindow = XInternAtom( display->get(), "WM_DELETE_WINDOW", False );
+ XSetWMProtocols( display->get(), m_window, &m_wmDeleteWindow, 1 );
+
XWMHints wmHints;
XpmCreatePixmapFromData( display->get(), m_window,
(char **)hornetseye_xpm,
@@ -377,8 +376,8 @@ void X11Window::handleEvent( XEvent &event ) throw (Error)
paintEvent( true );
break;
case ClientMessage:
- if ( ( event.xclient.message_type == wmProtocols ) &&
- ( (Atom)event.xclient.data.l[0] == wmDeleteWindow ) ) {
+ if ( ( event.xclient.message_type == m_wmProtocols ) &&
+ ( (Atom)event.xclient.data.l[0] == m_wmDeleteWindow ) ) {
#ifndef NDEBUG
cerr << "Delete message" << endl;
#endif
@@ -430,8 +429,8 @@ void X11Window::keyEvent( XKeyEvent &xkey ) throw (Error)
VALUE X11Window::registerRubyClass( VALUE module )
{
cRubyClass = rb_define_class_under( module, "X11Window", rb_cObject );
- rb_define_singleton_method( cRubyClass, "new",
- RUBY_METHOD_FUNC( wrapNew ), 4 );
+ rb_define_singleton_method(cRubyClass, "new",
+ RUBY_METHOD_FUNC( wrapNew ), 5);
rb_define_method( cRubyClass, "title=",
RUBY_METHOD_FUNC( wrapSetTitle ), 1 );
rb_define_method( cRubyClass, "width",
@@ -453,7 +452,7 @@ void X11Window::deleteRubyObject( void *ptr )
}
VALUE X11Window::wrapNew( VALUE rbClass, VALUE rbDisplay, VALUE rbX11Output,
- VALUE rbWidth, VALUE rbHeight )
+ VALUE rbWidth, VALUE rbHeight, VALUE rbBorder )
{
VALUE retVal = Qnil;
try {
@@ -467,7 +466,7 @@ VALUE X11Window::wrapNew( VALUE rbClass, VALUE rbDisplay, VALUE rbX11Output,
x11Output );
X11WindowPtr ptr
( new X11Window( *display, (*x11Output)->painter(),
- NUM2INT( rbWidth ), NUM2INT( rbHeight ) ) );
+ NUM2INT( rbWidth ), NUM2INT( rbHeight ), 0, rbBorder == Qtrue ) );
retVal = Data_Wrap_Struct( rbClass, 0, X11Window::deleteRubyObject,
new X11WindowPtr( ptr ) );
} catch ( std::exception &e ) {
View
@@ -31,8 +31,8 @@ class X11Window
{
friend class X11Display;
public:
- X11Window( X11DisplayPtr display, X11PainterPtr painter,
- int width, int height, Window parent = 0 );
+ X11Window(X11DisplayPtr display, X11PainterPtr painter,
+ int width, int height, Window parent = 0, bool border = true);
virtual ~X11Window(void);
int width(void) const { return m_width; }
int height(void) const { return m_height; }
@@ -52,7 +52,7 @@ public:
static VALUE registerRubyClass( VALUE module );
static void deleteRubyObject( void *ptr );
static VALUE wrapNew( VALUE rbClass, VALUE rbDisplay, VALUE rbX11Output,
- VALUE rbWidth, VALUE rbHeight );
+ VALUE rbWidth, VALUE rbHeight, VALUE rbBorder );
static VALUE wrapSetTitle( VALUE rbSelf, VALUE rbTitle );
static VALUE wrapWidth( VALUE rbSelf );
static VALUE wrapHeight( VALUE rbSelf );
@@ -69,8 +69,8 @@ protected:
X11PainterPtr m_painter;
int m_width;
int m_height;
- Atom wmProtocols;
- Atom wmDeleteWindow;
+ Atom m_wmProtocols;
+ Atom m_wmDeleteWindow;
};
typedef boost::shared_ptr< X11Window > X11WindowPtr;
@@ -32,15 +32,16 @@ def new( name = ENV[ 'DISPLAY' ] )
def show( *args, &action )
options = args.last.is_a?( Hash ) ? args.pop : {}
- options = { :title => 'Hornetseye', :output => XImageOutput }.merge options
+ options = { :title => 'Hornetseye', :border => true,
+ :output => XImageOutput }.merge options
unless action
frame, width, height = *args
width ||= frame.width
height ||= ( width.to_f * frame.height / frame.width ).round
display = options[ :display ] || new
output = options[ :output ].new
output.write frame
- window = X11Window.new display, output, width, height
+ window = X11Window.new display, output, width, height, options
window.title = options[ :title ]
begin
window.show
@@ -56,7 +57,7 @@ def show( *args, &action )
width ||= result.shape[0]
height ||= ( width.to_f * result.shape[1] / result.shape[0] ).round
output = options[ :output ].new
- window = X11Window.new display, output, width, height
+ window = X11Window.new display, output, width, height, options
window.title = options[ :title ]
begin
window.show
@@ -0,0 +1,36 @@
+# hornetseye-xorg - Graphical output under X.Org
+# Copyright (C) 2011 Jan Wedekind
+#
+# 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
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Namespace of Hornetseye computer vision library
+module Hornetseye
+
+ class X11Window
+
+ class << self
+
+ alias_method :orig_new, :new
+
+ def new(display, output, width, height, options = {})
+ options = { :border => true }.merge options
+ orig_new display, output, width, height, options[:border]
+ end
+
+ end
+
+ end
+
+end
+
@@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
require 'hornetseye-xorg/x11display'
+require 'hornetseye-xorg/x11window'
require 'hornetseye-xorg/x11output'
require 'hornetseye-xorg/ximageoutput'
require 'hornetseye-xorg/opengloutput'

0 comments on commit 806df34

Please sign in to comment.