removed xdotool
This commit is contained in:
parent
85764fed2d
commit
162aa6d7ab
@ -1,12 +1,12 @@
|
|||||||
#Pokémon GO Automatizace - Nastavení
|
#Pokémon GO Automatizace - Nastavení
|
||||||
#Sun Dec 14 20:04:32 CET 2025
|
#Fri Dec 19 21:53:30 CET 2025
|
||||||
autoklik.count=500
|
autoklik.count=500
|
||||||
window.width=807
|
window.width=807
|
||||||
transfer.delay=0
|
transfer.delay=0
|
||||||
window.height=743
|
window.height=743
|
||||||
autoklik.x=2380
|
autoklik.x=2380
|
||||||
autoklik.y=1124
|
autoklik.y=1124
|
||||||
transfer.count=48
|
transfer.count=3
|
||||||
window.x=866
|
window.x=1127
|
||||||
autoklik.interval=100
|
autoklik.interval=100
|
||||||
window.y=237
|
window.y=697
|
||||||
|
|||||||
@ -3,9 +3,11 @@ package com.pokemongo;
|
|||||||
import java.awt.AWTException;
|
import java.awt.AWTException;
|
||||||
import java.awt.GraphicsDevice;
|
import java.awt.GraphicsDevice;
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
|
import java.awt.Insets;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.Robot;
|
import java.awt.Robot;
|
||||||
|
import java.awt.Toolkit;
|
||||||
import java.awt.event.InputEvent;
|
import java.awt.event.InputEvent;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -38,6 +40,23 @@ public class PokemonGoAutomation {
|
|||||||
loadButtonTemplates();
|
loadButtonTemplates();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zjistí insets displeje (offset zp ůsobený OS - panel, taskbar, apod.)
|
||||||
|
* Důležité pro Ubuntu s GNOME panelem na horní straně
|
||||||
|
*/
|
||||||
|
private Insets getScreenInsets() {
|
||||||
|
try {
|
||||||
|
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
||||||
|
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gd.getDefaultConfiguration());
|
||||||
|
System.out.println("Zjištěny OS insets: top=" + insets.top + ", left=" + insets.left +
|
||||||
|
", bottom=" + insets.bottom + ", right=" + insets.right);
|
||||||
|
return insets;
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Chyba při zjištění insets: " + e.getMessage());
|
||||||
|
return new Insets(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vrátí počet dosud transfernutých pokémonů
|
* Vrátí počet dosud transfernutých pokémonů
|
||||||
*/
|
*/
|
||||||
@ -382,65 +401,21 @@ public class PokemonGoAutomation {
|
|||||||
*/
|
*/
|
||||||
public boolean findPokemonGoWindow() {
|
public boolean findPokemonGoWindow() {
|
||||||
try {
|
try {
|
||||||
// Pro Linux - hledání okna pomocí xdotool
|
Rectangle bounds = WindowFinder.findWindowByName("Lenovo");
|
||||||
// Nejdříve najít ID okna, pak získat jeho geometrii
|
|
||||||
Process searchProcess = Runtime.getRuntime().exec(
|
|
||||||
new String[] { "bash", "-c", "xdotool search --name \"Lenovo|L78032\" | head -1" });
|
|
||||||
|
|
||||||
java.io.BufferedReader searchReader = new java.io.BufferedReader(
|
if (bounds != null && bounds.width > 0 && bounds.height > 0) {
|
||||||
new java.io.InputStreamReader(searchProcess.getInputStream()));
|
windowBounds = bounds;
|
||||||
|
|
||||||
String windowId = searchReader.readLine();
|
|
||||||
searchProcess.waitFor();
|
|
||||||
|
|
||||||
if (windowId != null && !windowId.trim().isEmpty()) {
|
|
||||||
System.out.println("Nalezeno okno s ID: " + windowId);
|
|
||||||
|
|
||||||
// Získat geometrii okna
|
|
||||||
Process geomProcess = Runtime.getRuntime().exec(
|
|
||||||
new String[] { "bash", "-c", "xdotool getwindowgeometry " + windowId.trim() });
|
|
||||||
|
|
||||||
java.io.BufferedReader geomReader = new java.io.BufferedReader(
|
|
||||||
new java.io.InputStreamReader(geomProcess.getInputStream()));
|
|
||||||
|
|
||||||
String line;
|
|
||||||
int x = 0, y = 0, width = 0, height = 0;
|
|
||||||
|
|
||||||
while ((line = geomReader.readLine()) != null) {
|
|
||||||
System.out.println("xdotool výstup: " + line);
|
|
||||||
if (line.contains("Position:")) {
|
|
||||||
String[] parts = line.split("Position: ")[1].split(",");
|
|
||||||
x = Integer.parseInt(parts[0].trim());
|
|
||||||
y = Integer.parseInt(parts[1].trim().split(" ")[0]);
|
|
||||||
} else if (line.contains("Geometry:")) {
|
|
||||||
String[] parts = line.split("Geometry: ")[1].split("x");
|
|
||||||
width = Integer.parseInt(parts[0].trim());
|
|
||||||
height = Integer.parseInt(parts[1].trim());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
geomProcess.waitFor();
|
|
||||||
|
|
||||||
if (width > 0 && height > 0) {
|
|
||||||
windowBounds = new Rectangle(x, y, width, height);
|
|
||||||
System.out.println("Nalezeno okno: " + windowBounds);
|
System.out.println("Nalezeno okno: " + windowBounds);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback - použití celé obrazovky
|
System.out.println("Okno Pokémon GO nebylo nalezeno.");
|
||||||
System.out.println("Okno nenalezeno, použiji celou obrazovku");
|
return false;
|
||||||
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
|
||||||
windowBounds = gd.getDefaultConfiguration().getBounds();
|
|
||||||
return true;
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Chyba při hledání okna: " + e.getMessage());
|
System.err.println("Chyba při hledání okna: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
// Použití celé obrazovky jako záložní varianta
|
return false;
|
||||||
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
|
||||||
windowBounds = gd.getDefaultConfiguration().getBounds();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -687,8 +662,10 @@ public class PokemonGoAutomation {
|
|||||||
* @return Absolutní pozice na obrazovce
|
* @return Absolutní pozice na obrazovce
|
||||||
*/
|
*/
|
||||||
private Point getAbsolutePoint(int relativeX, int relativeY) {
|
private Point getAbsolutePoint(int relativeX, int relativeY) {
|
||||||
int absoluteX = windowBounds.x + relativeX;
|
int xCorrection = 20;
|
||||||
int absoluteY = windowBounds.y + relativeY;
|
int yCorrection = 100;
|
||||||
|
int absoluteX = windowBounds.x + relativeX + xCorrection;
|
||||||
|
int absoluteY = windowBounds.y + relativeY + yCorrection;
|
||||||
return new Point(absoluteX, absoluteY);
|
return new Point(absoluteX, absoluteY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,19 @@ public class PositionPicker extends JWindow {
|
|||||||
public PositionPicker(PositionPickerListener listener) {
|
public PositionPicker(PositionPickerListener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
||||||
Rectangle bounds = gd.getDefaultConfiguration().getBounds();
|
Rectangle screenBounds = gd.getDefaultConfiguration().getBounds();
|
||||||
|
|
||||||
|
// Zjistit insets - offset zp ůsobený OS panelem/dashboardem
|
||||||
|
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gd.getDefaultConfiguration());
|
||||||
|
System.out.println("PositionPicker insets: top=" + insets.top + ", left=" + insets.left);
|
||||||
|
|
||||||
|
// Aplikovat insets na bounds
|
||||||
|
Rectangle bounds = new Rectangle(
|
||||||
|
screenBounds.x + insets.left,
|
||||||
|
screenBounds.y + insets.top,
|
||||||
|
screenBounds.width - insets.left - insets.right,
|
||||||
|
screenBounds.height - insets.top - insets.bottom
|
||||||
|
);
|
||||||
setBounds(bounds);
|
setBounds(bounds);
|
||||||
|
|
||||||
System.out.println("PositionPicker vytvořen: " + bounds);
|
System.out.println("PositionPicker vytvořen: " + bounds);
|
||||||
|
|||||||
231
src/main/java/com/pokemongo/WindowFinder.java
Normal file
231
src/main/java/com/pokemongo/WindowFinder.java
Normal file
@ -0,0 +1,231 @@
|
|||||||
|
package com.pokemongo;
|
||||||
|
|
||||||
|
import com.sun.jna.Library;
|
||||||
|
import com.sun.jna.Native;
|
||||||
|
import com.sun.jna.Pointer;
|
||||||
|
import com.sun.jna.Structure;
|
||||||
|
import com.sun.jna.ptr.IntByReference;
|
||||||
|
import com.sun.jna.ptr.PointerByReference;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pomocná třída pro hledání oken v Linux/X11 prostředí.
|
||||||
|
* Používá X11 API přes JNA bindings.
|
||||||
|
*/
|
||||||
|
public class WindowFinder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* X11 native library interface
|
||||||
|
*/
|
||||||
|
public interface X11 extends Library {
|
||||||
|
X11 INSTANCE = Native.load("X11", X11.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* X11 Window Attributes struktura
|
||||||
|
*/
|
||||||
|
class XWindowAttributes extends Structure {
|
||||||
|
public int x;
|
||||||
|
public int y;
|
||||||
|
public int width;
|
||||||
|
public int height;
|
||||||
|
public int border_width;
|
||||||
|
public int depth;
|
||||||
|
public Pointer visual;
|
||||||
|
public Pointer root;
|
||||||
|
public int class_;
|
||||||
|
public int bit_gravity;
|
||||||
|
public int win_gravity;
|
||||||
|
public int backing_pixel;
|
||||||
|
public int backing_planes;
|
||||||
|
public int backing_store;
|
||||||
|
public long backing_pixel_unused;
|
||||||
|
public int save_under;
|
||||||
|
public Pointer colormap;
|
||||||
|
public int map_installed;
|
||||||
|
public int map_state;
|
||||||
|
public long all_event_masks;
|
||||||
|
public long your_event_mask;
|
||||||
|
public long do_not_propagate_mask;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<String> getFieldOrder() {
|
||||||
|
return Arrays.asList("x", "y", "width", "height", "border_width", "depth",
|
||||||
|
"visual", "root", "class_", "bit_gravity", "win_gravity",
|
||||||
|
"backing_pixel", "backing_planes", "backing_store",
|
||||||
|
"backing_pixel_unused", "save_under", "colormap",
|
||||||
|
"map_installed", "map_state", "all_event_masks",
|
||||||
|
"your_event_mask", "do_not_propagate_mask");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// X11 funkce
|
||||||
|
// Display je Pointer (nije Structure)
|
||||||
|
Pointer XOpenDisplay(String displayName);
|
||||||
|
int XCloseDisplay(Pointer display);
|
||||||
|
long XDefaultRootWindow(Pointer display);
|
||||||
|
|
||||||
|
int XGetWindowAttributes(Pointer display, long window, XWindowAttributes attrs);
|
||||||
|
|
||||||
|
long XInternAtom(Pointer display, String atomName, boolean onlyIfExists);
|
||||||
|
|
||||||
|
int XQueryTree(Pointer display, long window,
|
||||||
|
PointerByReference root_return, PointerByReference parent_return,
|
||||||
|
PointerByReference children_return, IntByReference nchildren_return);
|
||||||
|
|
||||||
|
int XFetchName(Pointer display, long window, PointerByReference window_name_return);
|
||||||
|
|
||||||
|
Pointer XFree(Pointer ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Najde okno podle jeho názvu a vrátí jeho bounds
|
||||||
|
* @param searchPattern Pattern pro hledání (substring názvu okna)
|
||||||
|
* @return Rectangle s pozicí a velikostí okna, nebo null pokud nenalezeno
|
||||||
|
*/
|
||||||
|
public static Rectangle findWindowByName(String searchPattern) {
|
||||||
|
Pointer display = null;
|
||||||
|
try {
|
||||||
|
display = X11.INSTANCE.XOpenDisplay(null);
|
||||||
|
if (display == null) {
|
||||||
|
System.out.println("WindowFinder: Nelze se připojit k X11 displei");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("WindowFinder: Připojen k X11 displayu");
|
||||||
|
|
||||||
|
long rootWindow = X11.INSTANCE.XDefaultRootWindow(display);
|
||||||
|
long[] foundWindow = new long[1];
|
||||||
|
foundWindow[0] = 0;
|
||||||
|
|
||||||
|
searchWindowRecursive(display, rootWindow, searchPattern, foundWindow);
|
||||||
|
|
||||||
|
if (foundWindow[0] != 0) {
|
||||||
|
Rectangle bounds = getWindowBounds(display, foundWindow[0]);
|
||||||
|
if (bounds != null) {
|
||||||
|
System.out.println("WindowFinder: Okno nalezeno: " + bounds);
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("WindowFinder: Okno s názvem '" + searchPattern + "' nenalezeno");
|
||||||
|
return null;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("WindowFinder - Chyba: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
if (display != null) {
|
||||||
|
try {
|
||||||
|
X11.INSTANCE.XCloseDisplay(display);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("WindowFinder - Chyba při zavírání displeje: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rekurzivně hledá okno v stromě oken
|
||||||
|
*/
|
||||||
|
private static void searchWindowRecursive(Pointer display, long window,
|
||||||
|
String searchPattern, long[] result) {
|
||||||
|
if (result[0] != 0) {
|
||||||
|
return; // Okno již nalezeno
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String windowName = getWindowNameString(display, window);
|
||||||
|
if (windowName != null && windowName.contains(searchPattern)) {
|
||||||
|
result[0] = window;
|
||||||
|
System.out.println("WindowFinder: Nalezeno okno: '" + windowName + "' (XID: " + window + ")");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignorovat chyby při čtení jména okna
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hledat v potomcích
|
||||||
|
try {
|
||||||
|
PointerByReference root_return = new PointerByReference();
|
||||||
|
PointerByReference parent_return = new PointerByReference();
|
||||||
|
PointerByReference children_return = new PointerByReference();
|
||||||
|
IntByReference nchildren_return = new IntByReference();
|
||||||
|
|
||||||
|
int status = X11.INSTANCE.XQueryTree(display, window, root_return, parent_return,
|
||||||
|
children_return, nchildren_return);
|
||||||
|
|
||||||
|
if (status != 0 && nchildren_return.getValue() > 0) {
|
||||||
|
Pointer childrenPtr = children_return.getValue();
|
||||||
|
int numChildren = nchildren_return.getValue();
|
||||||
|
|
||||||
|
if (childrenPtr != null) {
|
||||||
|
// Čtení window IDs z pole
|
||||||
|
for (int i = 0; i < numChildren && result[0] == 0; i++) {
|
||||||
|
long childWindow = childrenPtr.getLong((long) i * 8); // 64-bit window IDs
|
||||||
|
|
||||||
|
if (childWindow != 0) {
|
||||||
|
searchWindowRecursive(display, childWindow, searchPattern, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uvolnit paměť
|
||||||
|
X11.INSTANCE.XFree(childrenPtr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignorovat chyby při hledání v potomcích
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Získá jméno okna jako String
|
||||||
|
*/
|
||||||
|
private static String getWindowNameString(Pointer display, long window) {
|
||||||
|
try {
|
||||||
|
PointerByReference namePtr = new PointerByReference();
|
||||||
|
int status = X11.INSTANCE.XFetchName(display, window, namePtr);
|
||||||
|
|
||||||
|
if (status != 0 && namePtr.getValue() != null) {
|
||||||
|
String name = namePtr.getValue().getString(0);
|
||||||
|
if (name != null && !name.isEmpty()) {
|
||||||
|
X11.INSTANCE.XFree(namePtr.getValue());
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
X11.INSTANCE.XFree(namePtr.getValue());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignorovat chyby
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Získá bounds okna (pozici a velikost)
|
||||||
|
*/
|
||||||
|
private static Rectangle getWindowBounds(Pointer display, long window) {
|
||||||
|
try {
|
||||||
|
X11.XWindowAttributes attrs = new X11.XWindowAttributes();
|
||||||
|
int status = X11.INSTANCE.XGetWindowAttributes(display, window, attrs);
|
||||||
|
|
||||||
|
if (status == 0) {
|
||||||
|
System.err.println("WindowFinder - Chyba při získávání window attributes");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("WindowFinder: Window bounds - x:" + attrs.x + " y:" + attrs.y +
|
||||||
|
" w:" + attrs.width + " h:" + attrs.height);
|
||||||
|
|
||||||
|
return new Rectangle(attrs.x, attrs.y, attrs.width, attrs.height);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("WindowFinder - Chyba při získávání bounds: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user