View | Details | Raw Unified | Return to bug 1163
Collapse All | Expand All

(-)a/src/newt/classes/com/jogamp/newt/Window.java (+23 lines)
Lines 47-52 import com.jogamp.nativewindow.CapabilitiesImmutable; Link Here
47
import com.jogamp.nativewindow.NativeWindow;
47
import com.jogamp.nativewindow.NativeWindow;
48
import com.jogamp.nativewindow.ScalableSurface;
48
import com.jogamp.nativewindow.ScalableSurface;
49
import com.jogamp.nativewindow.WindowClosingProtocol;
49
import com.jogamp.nativewindow.WindowClosingProtocol;
50
import com.jogamp.nativewindow.util.PixelRectangle;
50
import com.jogamp.nativewindow.util.Rectangle;
51
import com.jogamp.nativewindow.util.Rectangle;
51
import com.jogamp.nativewindow.util.RectangleImmutable;
52
import com.jogamp.nativewindow.util.RectangleImmutable;
52
import com.jogamp.nativewindow.util.SurfaceSize;
53
import com.jogamp.nativewindow.util.SurfaceSize;
Lines 399-404 public interface Window extends NativeWindow, WindowClosingProtocol, ScalableSur Link Here
399
    void setTitle(String title);
400
    void setTitle(String title);
400
401
401
    String getTitle();
402
    String getTitle();
403
    
404
    /**
405
     * Set window icon.<br>
406
     * 
407
     * <p>
408
     * The given icon will replace the default icon for this frame only.
409
     * If the icon is null the default icon will be used instead.<br/>
410
     * The default application icon can be set using the system properties with
411
     * the key 'newt.window.icons'. More informations on the default application
412
     * icon can be found in the Window class javadoc.
413
     * </p>
414
     * 
415
     * @param icon frame icon or null for default icon.
416
     */
417
    void setIcon(PixelRectangle icon);
418
419
    /**
420
     * Get window icon. <br>
421
     * 
422
     * @return window icon, can be null
423
     */
424
    PixelRectangle getIcon();
402
425
403
    /** @see #setPointerVisible(boolean) */
426
    /** @see #setPointerVisible(boolean) */
404
    boolean isPointerVisible();
427
    boolean isPointerVisible();
(-)a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java (+11 lines)
Lines 75-80 import jogamp.opengl.GLDrawableImpl; Link Here
75
import com.jogamp.common.GlueGenVersion;
75
import com.jogamp.common.GlueGenVersion;
76
import com.jogamp.common.util.VersionUtil;
76
import com.jogamp.common.util.VersionUtil;
77
import com.jogamp.common.util.locks.RecursiveLock;
77
import com.jogamp.common.util.locks.RecursiveLock;
78
import com.jogamp.nativewindow.util.PixelRectangle;
78
import com.jogamp.newt.MonitorDevice;
79
import com.jogamp.newt.MonitorDevice;
79
import com.jogamp.newt.NewtFactory;
80
import com.jogamp.newt.NewtFactory;
80
import com.jogamp.newt.Screen;
81
import com.jogamp.newt.Screen;
Lines 527-532 public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind Link Here
527
        return window.getLocationOnScreen(storage);
528
        return window.getLocationOnScreen(storage);
528
    }
529
    }
529
530
531
    @Override
532
    public void setIcon(PixelRectangle icon) {
533
        window.setIcon(icon);
534
    }
535
536
    @Override
537
    public PixelRectangle getIcon() {
538
        return window.getIcon();
539
    }
540
530
    // Hide methods here ..
541
    // Hide methods here ..
531
    protected class GLLifecycleHook implements WindowImpl.LifecycleHook {
542
    protected class GLLifecycleHook implements WindowImpl.LifecycleHook {
532
543
(-)a/src/newt/classes/jogamp/newt/WindowImpl.java (+22 lines)
Lines 182-187 public abstract class WindowImpl implements Window, NEWTEventConsumer Link Here
182
    private boolean nfs_alwaysOnTop; // non fullscreen alwaysOnTop setting
182
    private boolean nfs_alwaysOnTop; // non fullscreen alwaysOnTop setting
183
    private NativeWindow nfs_parent = null;          // non fullscreen parent, in case explicit reparenting is performed (offscreen)
183
    private NativeWindow nfs_parent = null;          // non fullscreen parent, in case explicit reparenting is performed (offscreen)
184
    private String title = "Newt Window";
184
    private String title = "Newt Window";
185
    private PixelRectangle icon = null; 
185
    private boolean undecorated = false;
186
    private boolean undecorated = false;
186
    private boolean alwaysOnTop = false;
187
    private boolean alwaysOnTop = false;
187
    private PointerIconImpl pointerIcon = null;
188
    private PointerIconImpl pointerIcon = null;
Lines 716-721 public abstract class WindowImpl implements Window, NEWTEventConsumer Link Here
716
717
717
    protected void setTitleImpl(final String title) {}
718
    protected void setTitleImpl(final String title) {}
718
719
720
    protected void setIconImpl(final PixelRectangle icon) {}
721
    
719
    /**
722
    /**
720
     * Translates the given window client-area coordinates with top-left origin
723
     * Translates the given window client-area coordinates with top-left origin
721
     * to screen coordinates in window units.
724
     * to screen coordinates in window units.
Lines 1739-1744 public abstract class WindowImpl implements Window, NEWTEventConsumer Link Here
1739
    }
1742
    }
1740
1743
1741
    @Override
1744
    @Override
1745
    public final PixelRectangle getIcon() {
1746
        return icon;
1747
    }
1748
    @Override
1749
    public final void setIcon(PixelRectangle icon) {
1750
        if(this.icon==icon) return;
1751
        
1752
        this.icon = icon;
1753
        if(0 != getWindowHandle()) {
1754
            if(icon==null){
1755
                //reset default icon
1756
                setIconImpl(null);
1757
            }else{
1758
                setIconImpl(icon);
1759
            }
1760
        }
1761
    }
1762
    
1763
    @Override
1742
    public final boolean isPointerVisible() {
1764
    public final boolean isPointerVisible() {
1743
        return pointerVisible;
1765
        return pointerVisible;
1744
    }
1766
    }
(-)a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java (+32 lines)
Lines 52-57 import com.jogamp.nativewindow.util.Point; Link Here
52
52
53
import com.jogamp.common.ExceptionUtils;
53
import com.jogamp.common.ExceptionUtils;
54
import com.jogamp.common.nio.Buffers;
54
import com.jogamp.common.nio.Buffers;
55
import com.jogamp.nativewindow.util.DimensionImmutable;
56
import com.jogamp.nativewindow.util.PixelRectangle;
55
import com.jogamp.nativewindow.x11.X11GraphicsDevice;
57
import com.jogamp.nativewindow.x11.X11GraphicsDevice;
56
import com.jogamp.nativewindow.x11.X11GraphicsScreen;
58
import com.jogamp.nativewindow.x11.X11GraphicsScreen;
57
import com.jogamp.newt.NewtFactory;
59
import com.jogamp.newt.NewtFactory;
Lines 276-281 public class WindowDriver extends WindowImpl { Link Here
276
            }
278
            }
277
        });
279
        });
278
    }
280
    }
281
    
282
    @Override
283
    protected void setIconImpl(final PixelRectangle icon) {
284
        if(icon!=null){
285
            final DimensionImmutable size = icon.getSize();
286
            final int pixelDataSize = size.getWidth() * size.getHeight() * icon.getPixelformat().comp.bytesPerPixel();
287
            final Buffer pixels = icon.getPixels();
288
289
            runWithLockedDisplayDevice( new DisplayImpl.DisplayRunnable<Object>() {
290
                @Override
291
                public Object run(final long dpy) {                
292
                    setWindowIcon0(dpy, getWindowHandle(),pixelDataSize,
293
                            pixels,Buffers.getDirectBufferByteOffset(pixels),true /* pixels_is_direct */);
294
                    return null;
295
                }
296
            });
297
        }else if(defaultIconData!=null){
298
            //set default icon
299
            runWithLockedDisplayDevice( new DisplayImpl.DisplayRunnable<Object>() {
300
                @Override
301
                public Object run(final long dpy) {                
302
                    setWindowIcon0(dpy, getWindowHandle(),defaultIconDataSize,
303
                            defaultIconData,Buffers.getDirectBufferByteOffset(defaultIconData),true /* pixels_is_direct */);
304
                    return null;
305
                }
306
            });
307
        }
308
    }
279
309
280
    @Override
310
    @Override
281
    protected void setPointerIconImpl(final PointerIconImpl pi) {
311
    protected void setPointerIconImpl(final PointerIconImpl pi) {
Lines 452-457 public class WindowDriver extends WindowImpl { Link Here
452
                                      int visualID, long javaObjectAtom, long windowDeleteAtom,
482
                                      int visualID, long javaObjectAtom, long windowDeleteAtom,
453
                                      int x, int y, int width, int height, boolean autoPosition, int flags,
483
                                      int x, int y, int width, int height, boolean autoPosition, int flags,
454
                                      int pixelDataSize, Object pixels, int pixels_byte_offset, boolean pixels_is_direct);
484
                                      int pixelDataSize, Object pixels, int pixels_byte_offset, boolean pixels_is_direct);
485
    private native long setWindowIcon0(long display, long windowHandle, int pixelDataSize, 
486
                                        Object pixels, int pixels_byte_offset, boolean pixels_is_direct);
455
    private native void CloseWindow0(long display, long windowHandle, long javaObjectAtom, long windowDeleteAtom /*, long kbdHandle*/, // XKB disabled for now
487
    private native void CloseWindow0(long display, long windowHandle, long javaObjectAtom, long windowDeleteAtom /*, long kbdHandle*/, // XKB disabled for now
456
                                     final int randr_event_base, final int randr_error_base);
488
                                     final int randr_event_base, final int randr_error_base);
457
    private native void reconfigureWindow0(long display, int screen_index, long parentWindowHandle, long windowHandle,
489
    private native void reconfigureWindow0(long display, int screen_index, long parentWindowHandle, long windowHandle,
(-)a/src/newt/native/X11Window.c (+33 lines)
Lines 692-697 JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_WindowDriver_CreateWindow0 Link Here
692
692
693
/*
693
/*
694
 * Class:     jogamp_newt_driver_x11_WindowDriver
694
 * Class:     jogamp_newt_driver_x11_WindowDriver
695
 * Method:    SetWindowIcon
696
 */
697
JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_WindowDriver_setWindowIcon0
698
  (JNIEnv *env, jobject obj, jlong display, jlong windowHandle, jint pixelDataSize, jobject pixels, 
699
        jint pixels_byte_offset, jboolean pixels_is_direct)
700
{
701
    Display * dpy = (Display *)(intptr_t)display;
702
    Window window = (Window)windowHandle;
703
 
704
    const unsigned char * pixelPtr = NULL;
705
706
    // NOTE: MUST BE DIRECT BUFFER, since _NET_WM_ICON Atom uses buffer directly!
707
    DBG_PRINT("X11: CreateWindow icon: size %d, pixels %p, offset %d, direct %d\n", pixelDataSize, (void*)pixels, pixels_byte_offset, pixels_is_direct);
708
    if( 0 < pixelDataSize && NULL != pixels ) {
709
        pixelPtr = (const unsigned char *) ( JNI_TRUE == pixels_is_direct ? 
710
                                                (*env)->GetDirectBufferAddress(env, pixels) : 
711
                                                (*env)->GetPrimitiveArrayCritical(env, pixels, NULL) );
712
        DBG_PRINT("X11: CreateWindow icon: NIO %p\n", pixelPtr);
713
        NewtWindows_setIcon(dpy, window, (int)pixelDataSize, pixelPtr+pixels_byte_offset);
714
    }
715
716
        XMapWindow(dpy, window);
717
        //XUnmapWindow(dpy, w);
718
        XSync(dpy, False);
719
        
720
    if( JNI_FALSE == pixels_is_direct && NULL != pixelPtr ) {
721
        (*env)->ReleasePrimitiveArrayCritical(env, pixels, (void*)pixelPtr, JNI_ABORT);  
722
    }
723
724
}
725
726
/*
727
 * Class:     jogamp_newt_driver_x11_WindowDriver
695
 * Method:    CloseWindow
728
 * Method:    CloseWindow
696
 * Signature: (JJ)V
729
 * Signature: (JJ)V
697
 */
730
 */

Return to bug 1163