Skip to content

Commit

Permalink
style: fix PR #72 code style and typo
Browse files Browse the repository at this point in the history
  • Loading branch information
isHarryh committed Aug 21, 2024
1 parent cf80e1f commit b8a7052
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 153 deletions.
13 changes: 0 additions & 13 deletions .idea/Ark-Pets.iml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

4 changes: 2 additions & 2 deletions core/src/cn/harryh/arkpets/ArkPets.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void create() {
hWndMine = HWndCtrlFactory.find(null, APP_TITLE);
hWndMine.setLayered(true);
if(config.window_style_topmost){
hWndMine.setTopMost(true);
hWndMine.setTopmost(true);
}
//hWndMine.setWindowExStyle(HWndCtrl.WS_EX_LAYERED | (config.window_style_topmost ? HWndCtrl.WS_EX_TOPMOST : 0));
promiseToolwindowStyle(1000);
Expand Down Expand Up @@ -385,7 +385,7 @@ private HWndCtrl<?> refreshWindowIndex() {
}
if (minWindow == null || minWindow.isEmpty()) {
// Set as the top window if there is no peer.
minWindow = HWndCtrlFactory.getTopMost();
minWindow = HWndCtrlFactory.getTopmost();
}
if (plane != null) {
// Set barriers according to the vertical line.
Expand Down
50 changes: 26 additions & 24 deletions core/src/cn/harryh/arkpets/hwnd/HWndCtrl.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** Copyright (c) 2022-2024, Harry Huang
/** Copyright (c) 2022-2024, Harry Huang, Litwak913
* At GPL-3.0 License
*/
package cn.harryh.arkpets.hwnd;
Expand All @@ -8,15 +8,16 @@


public abstract class HWndCtrl<T> {
public final T hWnd; //Platform HWND
public final T hWnd; // Platform HWnd
public final String windowText;
public final int posTop;
public final int posBottom;
public final int posLeft;
public final int posRight;
public final int windowWidth;
public final int windowHeight;
public HWndCtrl(){

public HWndCtrl() {
hWnd = null;
windowText = "";
posTop = 0;
Expand All @@ -26,6 +27,7 @@ public HWndCtrl(){
windowWidth = 0;
windowHeight = 0;
}

public HWndCtrl(T hWnd) {
this.hWnd = hWnd;
windowText = getWindowText(hWnd);
Expand All @@ -34,8 +36,8 @@ public HWndCtrl(T hWnd) {
posBottom = rect.bottom;
posLeft = rect.left;
posRight = rect.right;
windowWidth = posRight-posLeft;
windowHeight = posBottom-posTop;
windowWidth = posRight - posLeft;
windowHeight = posBottom - posTop;
}

/** Returns window rect.
Expand Down Expand Up @@ -101,23 +103,20 @@ public float getCenterY() {
*/
public abstract void setWindowTransparent(boolean transparent);

/**
* Sets the window is a tool window.
* @param enable Whether the window is a tool window.
/** Sets the window's tool window style.
* @param enable Whether to enable the tool window style.
*/
public abstract void setToolWindow(boolean enable);

/**
* Sets the window is layered.
* @param enable Whether the window is layered.
/** Sets the window's layered style.
* @param enable Whether to enable the window's layered style.
*/
public abstract void setLayered(boolean enable);

/**
* Sets the window is topmost.
* @param enable Whether the window is topmost.
/** Sets the window's topmost style.
* @param enable Whether to enable the topmost style.
*/
public abstract void setTopMost(boolean enable);
public abstract void setTopmost(boolean enable);

/** Sends a mouse event message to the window.
* @param msg The window message value.
Expand Down Expand Up @@ -180,7 +179,7 @@ public String getIdleTitle() {
if (HWndCtrlFactory.find(null, title) == null) {
return title;
} else {
for (int cur = 2; cur <= 1024 ; cur ++) {
for (int cur = 2; cur <= 1024; cur++) {
title = String.format(numberedNameFormat, cur);
if (HWndCtrlFactory.find(null, title) == null)
return title;
Expand All @@ -190,21 +189,24 @@ public String getIdleTitle() {
}
}

public static class WindowRect{
public static class WindowRect {
public int top;
public int bottom;
public int right;
public int left;
public WindowRect(){}
public WindowRect(int x,int y,int h,int w){
this.top=y;
this.left=x;
this.bottom=y+h;
this.right=x+w;

public WindowRect() {
}

public WindowRect(int x, int y, int h, int w) {
this.top = y;
this.left = x;
this.bottom = y + h;
this.right = x + w;
}
}

public enum MouseEvent{
public enum MouseEvent {
EMPTY,
MOUSEMOVE,
LBUTTONDOWN,
Expand Down
80 changes: 41 additions & 39 deletions core/src/cn/harryh/arkpets/hwnd/HWndCtrlFactory.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/** Copyright (c) 2022-2024, Harry Huang, Litwak913
* At GPL-3.0 License
*/
package cn.harryh.arkpets.hwnd;

import cn.harryh.arkpets.utils.Logger;
Expand All @@ -9,8 +12,9 @@


public class HWndCtrlFactory {
private static WindowSystem platform;
public static HWndCtrl<?> EMPTY;
private static WindowSystem PLATFORM;

public enum WindowSystem {
AUTO,
USER32,
Expand All @@ -20,15 +24,16 @@ public enum WindowSystem {
QUARTZ,
NULL
}
public static WindowSystem detectWindowSystem(){
if(Platform.isWindows()){

public static WindowSystem detectWindowSystem() {
if (Platform.isWindows()) {
return WindowSystem.USER32;
} else if (Platform.isMac()) {
return WindowSystem.QUARTZ;
} else if (Platform.isLinux()) {
String desktop=System.getenv("XDG_CURRENT_DESKTOP");
String type=System.getenv("XDG_SESSION_TYPE");
if (desktop.equals("GNOME")){
String desktop = System.getenv("XDG_CURRENT_DESKTOP");
String type = System.getenv("XDG_SESSION_TYPE");
if (desktop.equals("GNOME")) {
return WindowSystem.MUTTER;
} else if (desktop.equals("KDE")) {
return WindowSystem.KWIN;
Expand All @@ -39,43 +44,41 @@ public static WindowSystem detectWindowSystem(){
return WindowSystem.NULL;
}

/**
* Init window system.
/** Init window system.
*/
public static void init(){
platform=detectWindowSystem();
Logger.info("System","Using "+platform.toString()+" Window System");
public static void init() {
PLATFORM = detectWindowSystem();
Logger.info("System", "Using " + PLATFORM.toString() + " Window System");
//establish connection
switch (platform){
switch (PLATFORM) {
case MUTTER -> {
//todo
}
}
EMPTY=create();
EMPTY = create();
}
/**
* Find a window.

/** Finds a window.
* @param className window's class name.
* @param windowName window's title.
* @return HWndCtrl
*/
public static HWndCtrl<?> find(String className, String windowName){
switch (platform){
public static HWndCtrl<?> find(String className, String windowName) {
switch (PLATFORM) {
case USER32 -> {
return User32HWndCtrl.find(className,windowName);
return User32HWndCtrl.find(className, windowName);
}
default -> {
return new NullHWndCtrl();
}
}
}

/**
* Create empty HWndCtrl.
/** Create empty HWndCtrl.
* @return empty HWndCtrl
*/
public static HWndCtrl<?> create(){
switch (platform){
public static HWndCtrl<?> create() {
switch (PLATFORM) {
case USER32 -> {
return new User32HWndCtrl();
}
Expand All @@ -84,31 +87,31 @@ public static HWndCtrl<?> create(){
}
}
}

/** Gets the current list of windows.
* @param only_visible Whether exclude the invisible window.
* @return An ArrayList consists of HWndCtrls.
*/
public static List<? extends HWndCtrl<?>> getWindowList(boolean only_visible){
switch (platform){
public static List<? extends HWndCtrl<?>> getWindowList(boolean only_visible) {
switch (PLATFORM) {
case USER32 -> {
return User32HWndCtrl.getWindowList(only_visible);
}
default-> {
default -> {
return new ArrayList<>();
}
}
}

/**
* Gets the topmost window.
/** Gets the topmost window.
* @return The topmost window's HWndCtrl.
*/
public static HWndCtrl<?> getTopMost(){
switch (platform){
public static HWndCtrl<?> getTopmost() {
switch (PLATFORM) {
case USER32 -> {
return User32HWndCtrl.getTopMost();
return User32HWndCtrl.getTopmost();
}
default-> {
default -> {
return new NullHWndCtrl();
}
}
Expand All @@ -117,26 +120,25 @@ public static HWndCtrl<?> getTopMost(){
/** Gets a new HWndCtrl which contains the updated information of this window.
* @return The up-to-dated HWndCtrl.
*/
public static HWndCtrl<?> update(HWndCtrl<?> old){
switch (platform){
public static HWndCtrl<?> update(HWndCtrl<?> old) {
switch (PLATFORM) {
case USER32 -> {
return new User32HWndCtrl((WinDef.HWND) old.hWnd);
}
default-> {
default -> {
return new NullHWndCtrl();
}
}
}

/** Free all resources.
/** Frees all resources.
*/
public static void free(){
switch (platform){
public static void free() {
switch (PLATFORM) {
case X11 -> {
//todo
}
default-> {
return;
default -> {
}
}
}
Expand Down
18 changes: 7 additions & 11 deletions core/src/cn/harryh/arkpets/hwnd/NullHWndCtrl.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/** Copyright (c) 2022-2024, Harry Huang, Litwak913
* At GPL-3.0 License
*/
package cn.harryh.arkpets.hwnd;

public class NullHWndCtrl extends HWndCtrl<Object>{

public class NullHWndCtrl extends HWndCtrl<Object> {
@Override
public WindowRect getWindowRect(Object hWnd) {
return new WindowRect(0,0,0,0);
return new WindowRect(0, 0, 0, 0);
}

@Override
Expand Down Expand Up @@ -33,41 +37,33 @@ public boolean close(int timeout) {

@Override
public void setForeground() {

}

@Override
public void setWindowAlpha(float alpha) {

}

@Override
public void setWindowPosition(HWndCtrl<Object> insertAfter, int x, int y, int w, int h) {

}

@Override
public void setWindowTransparent(boolean transparent) {

}

@Override
public void setToolWindow(boolean enable) {

}

@Override
public void setLayered(boolean enable) {

}

@Override
public void setTopMost(boolean enable) {

public void setTopmost(boolean enable) {
}

@Override
public void sendMouseEvent(MouseEvent msg, int x, int y) {

}
}
Loading

0 comments on commit b8a7052

Please sign in to comment.