<commit_before>package nallar.transparentwindows

import com.sun.jna.Native
import com.sun.jna.Pointer
import com.sun.jna.platform.win32.User32
import com.sun.jna.platform.win32.WinDef
import com.sun.jna.platform.win32.WinDef.HWND
import com.sun.jna.platform.win32.WinDef.RECT
import com.sun.jna.platform.win32.WinUser
import nallar.transparentwindows.jna.User32Fast
import nallar.transparentwindows.jna.WindowWrapper
import java.awt.*
import java.awt.event.ActionListener
import java.util.*
import java.util.concurrent.atomic.AtomicReference
import javax.swing.JOptionPane

object TransparentWindows {
	private val POLLING_MS = 100L
	private val mainThreadRun = AtomicReference<Runnable>()
	val forceFullTrans = 255
	private var exit: Boolean = false
	private var lastActive: HWND? = null
	private var mainThread: Thread? = null
	private var trayIcon: TrayIcon? = null
	var activeTrans = 225
	var foreInactiveTrans = 225
	var backTrans = 0

	fun debugPrint(s: String) {
		println(s)
	}

	private fun exit() {
		exit = true
		mainThread!!.interrupt()
		Thread.sleep(POLLING_MS * 2)

		clearTransparencies()
		if (trayIcon != null)
			SystemTray.getSystemTray().remove(trayIcon)
		System.exit(0)
	}

	private fun setForeInactiveTrans(s: String) {
		val t = s.toInt()
		runInMainThread(Runnable { foreInactiveTrans = t; })
	}

	private fun runInMainThread(r: Runnable) {
		val run = Runnable {
			clearTransparencies()
			r.run()
		}
		while (!mainThreadRun.compareAndSet(null, run)) {
			Thread.sleep(POLLING_MS)
		}
	}

	private fun setupSystemTray() {
		val tray = SystemTray.getSystemTray()
		val image = Toolkit.getDefaultToolkit().getImage(TransparentWindows::class.java.getResource("/icon.png"))
		val listener = ActionListener { e -> exit() }
		val popup = PopupMenu()
		val defaultItem = MenuItem("Exit")
		defaultItem.addActionListener(listener)
		popup.add(defaultItem)
		val setForeInactiveTransItem = MenuItem("Set Inactive Transparency")
		setForeInactiveTransItem.addActionListener { setForeInactiveTrans(JOptionPane.showInputDialog("Set transparency level", foreInactiveTrans)) }
		popup.add(setForeInactiveTransItem)
		trayIcon = TrayIcon(image, "Transparent Windows", popup)
		trayIcon!!.addActionListener(listener)
		trayIcon!!.isImageAutoSize = true
		tray.add(trayIcon!!)

		Runtime.getRuntime().addShutdownHook(object : Thread() {
			override fun start() {
				exit()
			}
		})
	}

	private fun clearTransparencies() {<commit_msg>Exit menu item should be at bottom<commit_after>package nallar.transparentwindows

import com.sun.jna.Native
import com.sun.jna.Pointer
import com.sun.jna.platform.win32.User32
import com.sun.jna.platform.win32.WinDef
import com.sun.jna.platform.win32.WinDef.HWND
import com.sun.jna.platform.win32.WinDef.RECT
import com.sun.jna.platform.win32.WinUser
import nallar.transparentwindows.jna.User32Fast
import nallar.transparentwindows.jna.WindowWrapper
import java.awt.*
import java.awt.event.ActionListener
import java.util.*
import java.util.concurrent.atomic.AtomicReference
import javax.swing.JOptionPane

object TransparentWindows {
	private val POLLING_MS = 100L
	private val mainThreadRun = AtomicReference<Runnable>()
	val forceFullTrans = 255
	private var exit: Boolean = false
	private var lastActive: HWND? = null
	private var mainThread: Thread? = null
	private var trayIcon: TrayIcon? = null
	var activeTrans = 225
	var foreInactiveTrans = 225
	var backTrans = 0

	fun debugPrint(s: String) {
		println(s)
	}

	private fun exit() {
		exit = true
		mainThread!!.interrupt()
		Thread.sleep(POLLING_MS * 2)

		clearTransparencies()
		if (trayIcon != null)
			SystemTray.getSystemTray().remove(trayIcon)
		System.exit(0)
	}

	private fun setForeInactiveTrans(s: String) {
		val t = s.toInt()
		runInMainThread(Runnable { foreInactiveTrans = t; })
	}

	private fun runInMainThread(r: Runnable) {
		val run = Runnable {
			clearTransparencies()
			r.run()
		}
		while (!mainThreadRun.compareAndSet(null, run)) {
			Thread.sleep(POLLING_MS)
		}
	}

	private fun setupSystemTray() {
		val tray = SystemTray.getSystemTray()
		val image = Toolkit.getDefaultToolkit().getImage(TransparentWindows::class.java.getResource("/icon.png"))
		val listener = ActionListener { e -> exit() }
		val popup = PopupMenu()
		val setForeInactiveTransItem = MenuItem("Set Inactive Transparency")
		setForeInactiveTransItem.addActionListener { setForeInactiveTrans(JOptionPane.showInputDialog("Set transparency level", foreInactiveTrans)) }
		popup.add(setForeInactiveTransItem)
		val defaultItem = MenuItem("Exit")
		defaultItem.addActionListener(listener)
		popup.add(defaultItem)
		trayIcon = TrayIcon(image, "Transparent Windows", popup)
		trayIcon!!.addActionListener(listener)
		trayIcon!!.isImageAutoSize = true
		tray.add(trayIcon!!)

		Runtime.getRuntime().addShutdownHook(object : Thread() {
			override fun start() {
				exit()
			}
		})
	}

	private fun clearTransparencies() {
{'fraction_non_alphanumeric': 0.10648242227189596, 'fraction_numerical': 0.011786222312538102, 'mean_word_length': 5.00976800976801, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2368335', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1618, 'n_words': 334}