Forráskód Böngészése

remove blur - temporal, no working, need grab screen

milan jurkulák 2 éve
szülő
commit
13b1f9aee8

+ 1 - 2
src/main/kotlin/eu/mjdev/desktop/components/file/FolderView.kt

@@ -26,7 +26,6 @@ import eu.mjdev.desktop.provider.DesktopScope.Companion.withDesktopScope
 import java.io.File
 import kotlin.math.max
 
-// ScreencastHelper
 // DefaultShellFolder
 // ShellFolder
 // Clipboard
@@ -47,7 +46,7 @@ fun FolderView(
     iconSpacing: Dp = 2.dp,
     iconSize: DpSize = DpSize(128.dp, 128.dp),
     path: File? = File("/"),
-    orientation: Orientation = Orientation.Vertical,
+    orientation: Orientation = Orientation.Vertical, // todo
     guideVisibleState: VisibilityState = rememberVisibilityState(false),
 ) = withDesktopScope {
     val files by rememberFiles(path, api.homeDir, showHidden, directoryFirst, showHomeFolder)

+ 0 - 9
src/main/kotlin/eu/mjdev/desktop/components/grid/GridPlaced.kt

@@ -2,16 +2,11 @@ package eu.mjdev.desktop.components.grid
 
 import androidx.compose.runtime.Composable
 import androidx.compose.ui.Modifier
-import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.layout.Layout
 import androidx.compose.ui.unit.Constraints
-import androidx.compose.ui.unit.Dp
-import androidx.compose.ui.unit.dp
 import eu.mjdev.desktop.components.grid.base.*
 import eu.mjdev.desktop.components.grid.base.Measure.calculateCellPlaces
 import eu.mjdev.desktop.components.grid.base.Measure.measure
-import eu.mjdev.desktop.components.sliding.base.VisibilityState
-import eu.mjdev.desktop.components.sliding.base.VisibilityState.Companion.rememberVisibilityState
 import kotlin.math.min
 
 @Composable
@@ -19,10 +14,6 @@ fun GridPlaced(
     cells: GridPlacedCells,
     modifier: Modifier = Modifier,
     placementPolicy: GridPlacedPlacementPolicy = GridPlacedPlacementPolicy.DEFAULT,
-    guideVisible: Boolean = true,
-    guideVisibleState: VisibilityState = rememberVisibilityState(guideVisible),
-    guideLineColor: Color = Color.Black,
-    guideLineSize: Dp = 1.dp,
     content: GridPlacedScope.() -> Unit
 ) {
     val scopeContent: GridPlacedScopeImpl = GridPlacedScopeImpl(cells, placementPolicy).apply(content)

+ 1 - 1
src/main/kotlin/eu/mjdev/desktop/windows/Window.kt

@@ -48,7 +48,7 @@ fun Window(
     alwaysOnTop: Boolean = false,
     alwaysOnBottom: Boolean = false,
     closeAction: Int = JFrame.DO_NOTHING_ON_CLOSE,
-    blurEnabled: Boolean = true,
+    blurEnabled: Boolean = false, // todo
     focusHelper: WindowFocusHelper,
     stateHelper: WindowStateHelper,
     onPreviewKeyEvent: (KeyEvent) -> Boolean = { false },

+ 37 - 68
src/main/kotlin/eu/mjdev/desktop/windows/blur/base/HackedContentPane.kt

@@ -1,86 +1,55 @@
 package eu.mjdev.desktop.windows.blur.base
 
-import java.awt.AlphaComposite
-import java.awt.Graphics
-import java.awt.Graphics2D
-import java.awt.image.BufferedImage
+import javax.swing.JFrame
 import javax.swing.JPanel
 
 @Suppress("MemberVisibilityCanBePrivate", "unused")
-class HackedContentPane : JPanel() {
-    private var image: BufferedImage? = null
-
-//    var jlayer: JLayer<JComponent> = JLayer(JPanel(), BlurLayerUI())
+class HackedContentPane(
+    val window: JFrame?
+) : JPanel() {
+//    val glassPanel = GlassPanel(window)
+//    var blurImage: BufferedImage? = null
 
     init {
         isOpaque = false
-//        setLayout(BorderLayout())
-//        add(jlayer)
-    }
-
-    fun setImage(image: BufferedImage?) {
-        this.image = image
+//        add(glassPanel)
     }
 
-    fun clear() = setImage(null)
-
-    // todo not painting nothing somehow
-    override fun paint(g: Graphics) {
-        if ((width <= 0) || (height <= 0)) {
-            return
-        }
-        val gg = g.create()
-        try {
-            if (background.alpha != 255) {
-                gg.color = background
-                if (gg is Graphics2D) {
-                    gg.composite = AlphaComposite.getInstance(AlphaComposite.SRC)
-                }
-                gg.fillRect(0, 0, width, height)
-            }
-            if (image != null) {
-                g.drawImage(image, 0, 0, width, height, null)
-            }
-        } finally {
-            gg.dispose()
-        }
-        super.paint(g)
+    fun repaintBlur() {
+//        if (window != null && window.width > 0 && window.height > 0) {
+//            println("creating blur image")
+//            BufferedImage(
+//                window.width,
+//                window.height,
+//                BufferedImage.TYPE_INT_ARGB
+//            ).also { image ->
+//                window.paint(image.graphics)
+//                GaussianFilter(5f).filter(image, null)
+//            }.also { blurBuffer ->
+//                blurImage = blurBuffer
+//            }
+//            glassPanel.setSize(window.width, window.height)
+//        } else {
+//            glassPanel.setSize(0, 0)
+//        }
     }
 
-//    class BlurLayerUI : LayerUI<JComponent>() {
-//        private var mOffscreenImage: BufferedImage? = null
-//        private val mOperation: BufferedImageOp
-//
+//    inner class GlassPanel(
+//        private var window: JFrame?
+//    ) : JLabel() {
 //        init {
-//            val ninth = 1.0f / 9.0f
-//            val blurKernel = floatArrayOf(
-//                ninth, ninth, ninth, ninth, ninth, ninth,
-//                ninth, ninth, ninth
-//            )
-//            mOperation = ConvolveOp(
-//                Kernel(3, 3, blurKernel),
-//                ConvolveOp.EDGE_NO_OP, null
-//            )
+//            isOpaque = false
+//            setSize(window?.width ?: 0, window?.height ?: 0)
 //        }
 //
-//        override fun paint(g: Graphics, c: JComponent) {
-//            val w = c.width
-//            val h = c.height
-//            if (w == 0 || h == 0) {
-//                return
-//            }
-//            if (mOffscreenImage == null || mOffscreenImage!!.width != w || mOffscreenImage!!.height != h) {
-//                mOffscreenImage = BufferedImage(
-//                    w, h,
-//                    BufferedImage.TYPE_INT_RGB
-//                )
+//        override fun paintComponent(g: Graphics?) {
+//            println("paint called")
+//            if (window != null && blurImage != null && width > 1 && height > 1) {
+//                println("painting blur")
+//                g?.color = Color.WHITE
+//                g?.fillRect(0,0,window!!.width, window!!.height)
+//                g?.drawImage(blurImage, 0, 0, window!!.width, window!!.height, null)
 //            }
-//            val ig2 = mOffscreenImage!!.createGraphics()
-//            ig2.clip = g.clip
-//            super.paint(ig2, c)
-//            ig2.dispose()
-//            val g2 = g as Graphics2D
-//            g2.drawImage(mOffscreenImage, mOperation, 0, 0)
 //        }
 //    }
-}
+}

+ 0 - 128
src/main/kotlin/eu/mjdev/desktop/windows/blur/linux/BlurApp.kt

@@ -1,128 +0,0 @@
-/*
- * Copyright (c) Milan Jurkulák 2024.
- *  Contact:
- *  e: mimoccc@gmail.com
- *  e: mj@mjdev.org
- *  w: https://mjdev.org
- */
-package eu.mjdev.desktop.windows.blur.linux
-
-import eu.mjdev.desktop.helpers.image.filters.GaussianFilter
-import java.awt.*
-import java.awt.event.ActionEvent
-import java.awt.event.ActionListener
-import java.awt.image.BufferedImage
-import javax.swing.JButton
-import javax.swing.JFrame
-import javax.swing.JPanel
-import javax.swing.SwingUtilities
-
-@Suppress("UNUSED_VARIABLE")
-class BlurApp : ActionListener {
-    var jf: JFrame = JFrame("Example")
-    var background: JPanel = object : JPanel() {
-        override fun paintComponent(g: Graphics) {
-            val g2d = g as Graphics2D
-            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
-            val w = width
-            val h = height
-            val c1 = Color(41, 59, 102)
-            val c2 = Color(2, 2, 2)
-            val gp = GradientPaint(0f, 0f, c1, 0f, (h - 20).toFloat(), c2)
-            g2d.paint = gp
-            g2d.fillRect(0, 0, w, h)
-        }
-    }
-    private var glassPanel: JPanel
-    var button: JButton = JButton("Click me!")
-    private var another: JButton = JButton("Close")
-    var blurBuffer: BufferedImage? = null
-    var backBuffer: BufferedImage? = null
-    var currentGraphics: BufferedImage? = null
-    var alpha: Float = 0.0f
-
-    init {
-        button.addActionListener(this)
-        another.addActionListener(this)
-        jf.setSize(900, 400)
-        jf.setLocationRelativeTo(null)
-        jf.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
-        jf.add(background)
-        jf.add(button, BorderLayout.NORTH)
-        glassPanel = BlurPanel()
-        jf.glassPane = glassPanel
-        jf.isVisible = true
-    }
-
-    override fun actionPerformed(e: ActionEvent) {
-        if (e.source === button) {
-            createBlur()
-            jf.glassPane.isVisible = true
-            val root = SwingUtilities.getRootPane(jf)
-            currentGraphics = BufferedImage(root.width, root.height, BufferedImage.TYPE_3BYTE_BGR)
-            jf.glassPane.isVisible = false
-            glassPanel = GlassPanel()
-            jf.glassPane.isVisible = true
-        }
-        if (e.source === another) {
-            jf.glassPane.isVisible = false
-        }
-    }
-
-    inner class BlurPanel : JPanel() {
-        override fun paintComponent(g: Graphics) {
-            if (isVisible && blurBuffer != null) {
-                val g2d = g.create() as Graphics2D
-                g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR)
-                g2d.drawImage(backBuffer, 0, 0, null)
-                g2d.composite = AlphaComposite.SrcOver.derive(alpha)
-                println(alpha)
-                println("Function called 1")
-                g2d.drawImage(blurBuffer, 0, 0, jf.width, jf.height, null)
-                g2d.dispose()
-            }
-        }
-    }
-
-    private fun createBlur() {
-        alpha = 1.0f
-        val root = SwingUtilities.getRootPane(jf)
-        blurBuffer = BufferedImage(jf.width, jf.height, BufferedImage.TYPE_INT_ARGB)
-        val g2d = blurBuffer!!.createGraphics()
-        root.paint(g2d)
-        g2d.dispose()
-        backBuffer = blurBuffer
-        blurBuffer = GaussianFilter(5f).filter(blurBuffer, null)
-    }
-
-    inner class GlassPanel : JPanel() {
-        init {
-            isOpaque = false
-        }
-
-        override fun paintComponent(g: Graphics) {
-            val x = 34
-            val y = 34
-            val w = width - 68
-            val h = height - 68
-            val arc = 30
-            var g2 = currentGraphics!!.createGraphics()
-            g2.drawImage(currentGraphics, 0, 0, null)
-            g2 = g.create() as Graphics2D
-            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
-            g2.color = Color(0, 0, 0, 220)
-            g2.fillRoundRect(x, y, w, h, arc, arc)
-            g2.stroke = BasicStroke(1f)
-            g2.color = Color.WHITE
-            g2.drawRoundRect(x, y, w, h, arc, arc)
-            g2.dispose()
-        }
-    }
-
-    companion object {
-        @JvmStatic
-        fun main(args: Array<String>) {
-            val n = BlurApp()
-        }
-    }
-}

+ 0 - 46
src/main/kotlin/eu/mjdev/desktop/windows/blur/linux/BlurBackground.kt

@@ -1,46 +0,0 @@
-package eu.mjdev.desktop.windows.blur.linux
-
-import eu.mjdev.desktop.helpers.image.filters.GaussianFilter
-import eu.mjdev.desktop.windows.blur.base.HackedContentPane
-import eu.mjdev.desktop.windows.blur.linux.LinuxWindowBlurManager.Companion.contentPane
-import java.awt.Container
-import java.awt.Window
-import java.awt.image.BufferedImage
-
-object BlurBackground {
-    fun applyBlurBackground(
-        window: Window,
-        blurRadius: Float = 3f,
-        contentPane: Container? = window.contentPane
-    ) {
-//        val toolkit = Toolkit.getDefaultToolkit()
-        val hackedPane = contentPane as? HackedContentPane
-        val isHacked = hackedPane != null
-        val width = window.width
-        val height = window.height
-        if (isHacked && (width > 0) && (height > 0)) {
-            try {
-                BufferedImage(
-                    width,
-                    height,
-                    BufferedImage.TYPE_INT_ARGB
-                ).let { image ->
-                    with(image.graphics) {
-                        hackedPane?.paint(this)
-                        GaussianFilter(
-                            blurRadius
-                        ).filter(
-                            image,
-                            null
-                        ).let { blurredImage ->
-                            hackedPane?.setImage(blurredImage)
-                        }
-                        dispose()
-                    }
-                }
-            } catch (e: Throwable) {
-                e.printStackTrace()
-            }
-        }
-    }
-}

+ 15 - 15
src/main/kotlin/eu/mjdev/desktop/windows/blur/linux/LinuxWindowBlurManager.kt

@@ -12,7 +12,10 @@ import java.awt.event.ComponentAdapter
 import java.awt.event.ComponentEvent
 import java.lang.reflect.Field
 import java.lang.reflect.Method
-import javax.swing.*
+import javax.swing.JDialog
+import javax.swing.JFrame
+import javax.swing.JWindow
+import javax.swing.SwingUtilities
 
 @Suppress("MemberVisibilityCanBePrivate")
 class LinuxWindowBlurManager(
@@ -38,17 +41,19 @@ class LinuxWindowBlurManager(
     }
 
     private fun updateBlur() {
-        BlurBackground.applyBlurBackground(window)
+        if (blurEnabled) {
+            (window.contentPane as? HackedContentPane)?.repaintBlur()
+        }
     }
 
     val componentAdapter = object : ComponentAdapter() {
-        override fun componentMoved(e: ComponentEvent?) = resetBlur(e)
-        override fun componentResized(e: ComponentEvent?) = resetBlur(e)
-        override fun componentShown(e: ComponentEvent?) = resetBlur(e)
+        override fun componentMoved(e: ComponentEvent?) = updateBlur(e)
+        override fun componentResized(e: ComponentEvent?) = updateBlur(e)
+        override fun componentShown(e: ComponentEvent?) = updateBlur(e)
     }
 
     @Suppress("UNUSED_PARAMETER")
-    private fun resetBlur(e: AWTEvent?) {
+    private fun updateBlur(e: AWTEvent?) {
         if (blurEnabled) updateBlur()
     }
 
@@ -57,12 +62,6 @@ class LinuxWindowBlurManager(
     }
 
     companion object {
-//        val Window.isTransparent
-//            get() = when (this) {
-//                is ComposeWindow -> skiaLayer?.transparency
-//                else -> background.alpha != 255
-//            }
-
         var Window.contentPane
             get() = when (this) {
                 is JFrame -> contentPane
@@ -104,9 +103,8 @@ class LinuxWindowBlurManager(
         }
 
         fun Window.hackContentPane() {
-//            println("hacking window: ${this.name}")
             val oldContentPane = contentPane ?: return
-            val newContentPane: JComponent = HackedContentPane()
+            val newContentPane = HackedContentPane(this as? JFrame)
             newContentPane.name = "$name.contentPane"
             newContentPane.layout = object : BorderLayout() {
                 override fun addLayoutComponent(comp: Component, constraints: Any?) {
@@ -114,7 +112,9 @@ class LinuxWindowBlurManager(
                 }
             }
             newContentPane.background = java.awt.Color(0, 0, 0, 0)
-            oldContentPane.components.forEach { newContentPane.add(it) }
+            oldContentPane.components.forEach { c ->
+                newContentPane.add(c)
+            }
             contentPane = newContentPane
         }
     }