Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Linux: use X11 window manager events to move window and to show windo…
…w menu (right-click on window title bar), if custom window decorations are enabled (issue #482)
- Loading branch information
Showing
19 changed files
with
776 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ on: | |
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
if: false | ||
|
||
strategy: | ||
matrix: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2022 FormDev Software GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
plugins { | ||
`cpp-library` | ||
} | ||
|
||
library { | ||
// disable debuggable for release builds to make shared libraries smaller | ||
binaries.configureEach( CppSharedLibrary::class ) { | ||
with( compileTask.get() ) { | ||
if( name.contains( "Release" ) ) | ||
isDebuggable = false | ||
} | ||
with( linkTask.get() ) { | ||
if( name.contains( "Release" ) ) | ||
debuggable.set( false ) | ||
} | ||
} | ||
} | ||
|
||
tasks { | ||
withType<CppCompile>().configureEach { | ||
doFirst { | ||
println( "Used Tool Chain:" ) | ||
println( " - ${toolChain.get()}" ) | ||
println( "Available Tool Chains:" ) | ||
toolChains.forEach { | ||
println( " - $it" ) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2022 FormDev Software GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
open class JniHeadersExtension { | ||
var headers: List<String> = emptyList() | ||
} | ||
|
||
val extension = project.extensions.create<JniHeadersExtension>( "flatlafJniHeaders" ) | ||
|
||
|
||
tasks { | ||
register<Copy>( "jni-headers" ) { | ||
// depend on :flatlaf-core:compileJava because it generates the JNI headers | ||
dependsOn( ":flatlaf-core:compileJava" ) | ||
|
||
from( project( ":flatlaf-core" ).buildDir.resolve( "generated/jni-headers" ) ) | ||
into( "src/main/headers" ) | ||
include( extension.headers ) | ||
filter<org.apache.tools.ant.filters.FixCrLfFilter>( | ||
"eol" to org.apache.tools.ant.filters.FixCrLfFilter.CrLf.newInstance( "lf" ) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeLinuxLibrary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright 2022 FormDev Software GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.formdev.flatlaf.ui; | ||
|
||
import java.awt.Point; | ||
import java.awt.Toolkit; | ||
import java.awt.Window; | ||
import java.awt.event.MouseEvent; | ||
import java.awt.geom.AffineTransform; | ||
import javax.swing.JDialog; | ||
import javax.swing.JFrame; | ||
|
||
/** | ||
* Native methods for Linux. | ||
* <p> | ||
* <b>Note</b>: This is private API. Do not use! | ||
* | ||
* @author Karl Tauber | ||
* @since 2.5 | ||
*/ | ||
class FlatNativeLinuxLibrary | ||
{ | ||
static boolean isLoaded() { | ||
return FlatNativeLibrary.isLoaded(); | ||
} | ||
|
||
// direction for _NET_WM_MOVERESIZE message | ||
// see https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html | ||
static final int MOVE = 8; | ||
|
||
private static Boolean isXWindowSystem; | ||
|
||
private static boolean isXWindowSystem() { | ||
if( isXWindowSystem == null ) | ||
isXWindowSystem = Toolkit.getDefaultToolkit().getClass().getName().endsWith( ".XToolkit" ); | ||
return isXWindowSystem; | ||
} | ||
|
||
static boolean isWMUtilsSupported( Window window ) { | ||
return hasCustomDecoration( window ) && isXWindowSystem() && isLoaded(); | ||
} | ||
|
||
static boolean moveOrResizeWindow( Window window, MouseEvent e, int direction ) { | ||
Point pt = scale( window, e.getLocationOnScreen() ); | ||
return xMoveOrResizeWindow( window, pt.x, pt.y, direction ); | ||
|
||
/* | ||
try { | ||
Class<?> cls = Class.forName( "com.formdev.flatlaf.natives.jna.linux.X11WmUtils" ); | ||
java.lang.reflect.Method m = cls.getMethod( "xMoveOrResizeWindow", Window.class, int.class, int.class, int.class ); | ||
return (Boolean) m.invoke( null, window, pt.x, pt.y, direction ); | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
return false; | ||
} | ||
*/ | ||
} | ||
|
||
static boolean showWindowMenu( Window window, MouseEvent e ) { | ||
Point pt = scale( window, e.getLocationOnScreen() ); | ||
return xShowWindowMenu( window, pt.x, pt.y ); | ||
|
||
/* | ||
try { | ||
Class<?> cls = Class.forName( "com.formdev.flatlaf.natives.jna.linux.X11WmUtils" ); | ||
java.lang.reflect.Method m = cls.getMethod( "xShowWindowMenu", Window.class, int.class, int.class ); | ||
return (Boolean) m.invoke( null, window, pt.x, pt.y ); | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
return false; | ||
} | ||
*/ | ||
} | ||
|
||
private static Point scale( Window window, Point pt ) { | ||
AffineTransform transform = window.getGraphicsConfiguration().getDefaultTransform(); | ||
int x = (int) Math.round( pt.x * transform.getScaleX() ); | ||
int y = (int) Math.round( pt.y * transform.getScaleY() ); | ||
return new Point( x, y ); | ||
} | ||
|
||
// X Window System | ||
private static native boolean xMoveOrResizeWindow( Window window, int x, int y, int direction ); | ||
private static native boolean xShowWindowMenu( Window window, int x, int y ); | ||
|
||
private static boolean hasCustomDecoration( Window window ) { | ||
return (window instanceof JFrame && JFrame.isDefaultLookAndFeelDecorated() && ((JFrame)window).isUndecorated()) || | ||
(window instanceof JDialog && JDialog.isDefaultLookAndFeelDecorated() && ((JDialog)window).isUndecorated()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.