xpra icon
Bug tracker and wiki

Ticket #1794: osx-transparency.patch

File osx-transparency.patch, 4.9 KB (added by Antoine Martin, 3 years ago)

native calls to try to force transparency on

  • xpra/platform/darwin/transparency_glue.h

     
     1/**
     2 * This file is part of Xpra.
     3 * Copyright (C) 2018 Antoine Martin <antoine@devloop.org.uk>
     4 */
     5
     6//Just a wrapper for functions that are problematic to access with Cython
     7
     8#import <Cocoa/Cocoa.h>
     9
     10void setOpaque(NSWindow *window, BOOL opaque);
     11void setClearBackgroundColor(NSWindow *window);
     12
     13/*
     14void setAlphaValue(NSWindow *window, float alpha);
     15void setBackgroundColor(NSWindow *window, NSColor *color);
     16void invalidateShadow(NSWindow *window);
     17void setHasShadow(NSWindow *window, BOOL hasShadow);
     18*/
  • xpra/platform/darwin/transparency_glue.m

     
     1/**
     2 * This file is part of Xpra.
     3 * Copyright (C) 2018 Antoine Martin <antoine@devloop.org.uk>
     4 */
     5
     6#import <Cocoa/Cocoa.h>
     7
     8void setOpaque(NSWindow *window, BOOL opaque) {
     9        [window setOpaque:opaque];
     10}
     11void setClearBackgroundColor(NSWindow *window) {
     12        NSColor *color = [NSColor clearColor];
     13        [window setBackgroundColor:color];
     14}
     15void setBackgroundColor(NSWindow *window, NSColor *color) {
     16        [window setBackgroundColor:color];
     17}
     18
     19/*
     20void setAlphaValue(NSWindow *window, float alpha) {
     21        [window setAlphaValue:alpha];
     22}
     23void invalidateShadow(NSWindow *window) {
     24        [window invalidateShadow];
     25}
     26void setHasShadow(NSWindow *window, BOOL hasShadow) {
     27        [window setHasShadow:hasShadow];
     28}
     29*/
     30 No newline at end of file
  • setup.py

     
    17381738        add_to_keywords(quartz_pkgconfig, 'extra_compile_args',
    17391739                    "-ObjC",
    17401740                    "-framework", "AppKit",
     1741                    "-I/System/Library/Frameworks/Cocoa.framework/Versions/A/Headers/",
    17411742                    "-I/System/Library/Frameworks/AppKit.framework/Versions/C/Headers/")
    17421743        cython_add(Extension("xpra.platform.darwin.gdk3_bindings",
    1743                 ["xpra/platform/darwin/gdk3_bindings.pyx"],
     1744                ["xpra/platform/darwin/gdk3_bindings.pyx", "xpra/platform/darwin/transparency_glue.m"],
    17441745                language="objc",
    17451746                **quartz_pkgconfig
    17461747                ))
     
    17511752                    '-framework', 'Foundation',
    17521753                    '-framework', 'AppKit',
    17531754                    '-ObjC',
    1754                     "-I/System/Library/Frameworks/Cocoa.framework/Versions/A/Headers/Cocoa.h")
     1755                    "-I/System/Library/Frameworks/Cocoa.framework/Versions/A/Headers/")
    17551756        cython_add(Extension("xpra.platform.darwin.gdk_bindings",
    17561757                ["xpra/platform/darwin/gdk_bindings.pyx", "xpra/platform/darwin/nsevent_glue.m"],
    17571758                language="objc",
  • xpra/platform/darwin/gdk3_bindings.pyx

     
    1313
    1414from xpra.gtk_common.gtk3.gdk_bindings cimport get_gdkwindow
    1515
     16ctypedef float CGFloat
     17ctypedef int BOOL
     18
    1619cdef extern from "AppKit/AppKit.h":
     20    ctypedef struct NSColor:
     21        pass
     22    ctypedef struct NSWindow:
     23        pass
    1724    ctypedef struct NSView:
    1825        pass
    1926
     27cdef extern from "transparency_glue.h":
     28    #couldn't figure out how to get unions and cython+objc to play nice,
     29    #so we use a wrapper:
     30    void setAlphaValue(NSWindow *window, float alpha)
     31    void setOpaque(NSWindow *window, BOOL opaque)
     32    void setBackgroundColor(NSWindow *window, NSColor *color)
     33    void setClearBackgroundColor(NSWindow *window)
     34    void invalidateShadow(NSWindow *window)
     35    void setHasShadow(NSWindow *window, BOOL hasShadow)
     36
     37
    2038cdef extern from "gtk-3.0/gdk/gdkquartz.h":
    2139    NSView *gdk_quartz_window_get_nsview(GdkWindow *window)
     40    NSWindow *gdk_quartz_window_get_nswindow(GdkWindow *window)
    2241
     42
    2343cdef extern from "gtk-3.0/gdk/gdk.h":
    2444    ctypedef struct GdkWindow:
    2545        pass
    2646
     47cdef NSWindow *get_nswindow(pywindow):
     48    cdef GdkWindow *gdkwindow = get_gdkwindow(pywindow)
     49    assert gdkwindow
     50    cdef NSWindow *nswindow = gdk_quartz_window_get_nswindow(gdkwindow)
     51    return nswindow
    2752
    2853cdef NSView *get_nsview(pywindow):
    2954    cdef GdkWindow *gdkwindow = get_gdkwindow(pywindow)
     
    3459def get_nsview_ptr(pywindow):
    3560    cdef NSView *nsview = get_nsview(pywindow)
    3661    return <uintptr_t> nsview
     62
     63def enable_transparency(pywindow):
     64    cdef NSWindow *window = get_nswindow(pywindow)
     65    setOpaque(window, 0)
     66    setClearBackgroundColor(window)
     67    #setAlphaValue(window, 1.0)
     68    #setHasShadow(window, 0)
     69    #invalidateShadow(window)