Skip to content

Commit

Permalink
[Shared] Rename isValidCall -> onUIThread
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorOrachyov committed Aug 19, 2021
1 parent e51e6e5 commit 1505cb3
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 108 deletions.
22 changes: 11 additions & 11 deletions linux/java/org/jetbrains/jwm/WindowX11.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,71 +15,71 @@ public WindowX11() {

@Override
public void show() {
assert _isValidCall();
assert _onUIThread();
_nShow();
}

@Override
public Window setTextInputEnabled(boolean enabled) {
assert _isValidCall();
assert _onUIThread();
// TODO: impl me
return this;
}

@Override
public void unmarkText() {
assert _isValidCall();
assert _onUIThread();
// TODO: impl me!
}

@Override
public UIRect getWindowRect() {
assert _isValidCall();
assert _onUIThread();
return _nGetWindowRect();
}

@Override
public UIRect getContentRect() {
assert _isValidCall();
assert _onUIThread();
return _nGetContentRect();
}

@Override
public Window setWindowPosition(int left, int top) {
assert _isValidCall();
assert _onUIThread();
_nSetWindowPosition(left, top);
return this;
}

@Override
public Window setWindowSize(int width, int height) {
assert _isValidCall();
assert _onUIThread();
_nSetWindowSize(width, height);
return this;
}

@Override
public Window setContentSize(int width, int height) {
assert _isValidCall();
assert _onUIThread();
_nSetContentSize(width, height);
return this;
}

@Override
public float getScale() {
assert _isValidCall();
assert _onUIThread();
return _nGetScale();
}

@Override
public void requestFrame() {
assert _isValidCall();
assert _onUIThread();
_nRequestFrame();
}

@Override
public void close() {
assert _isValidCall();
assert _onUIThread();
_nClose();
super.close();
}
Expand Down
24 changes: 12 additions & 12 deletions macos/java/org/jetbrains/jwm/LayerMetal.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,68 +14,68 @@ public LayerMetal() {

@Override
public void attach(Window window) {
assert _isValidCall();
assert _onUIThread();
_window = window;
_nAttach(window);
}

@Override
public void reconfigure() {
assert _isValidCall();
assert _onUIThread();
_nReconfigure();
}

@Override
public void resize(int width, int height) {
assert _isValidCall();
assert _onUIThread();
_width = width;
_height = height;
_nResize(width, height);
}

@Override
public int getWidth() {
assert _isValidCall();
assert _onUIThread();
return _width;
}

@Override
public int getHeight() {
assert _isValidCall();
assert _onUIThread();
return _height;
}

@Override
public void swapBuffers() {
assert _isValidCall();
assert _onUIThread();
_nSwapBuffers();
}

@Override
public void close() {
assert _isValidCall();
assert _onUIThread();
_nClose();
_window = null;
super.close();
}

public long getDevicePtr() {
assert _isValidCall();
assert _onUIThread();
return _nGetDevicePtr();
}

public long getQueuePtr() {
assert _isValidCall();
assert _onUIThread();
return _nGetQueuePtr();
}

public long nextDrawableTexturePtr() {
assert _isValidCall();
assert _onUIThread();
return _nNextDrawableTexturePtr();
}

@ApiStatus.Internal public static boolean _isValidCall() {
return App._isValidCall();
@ApiStatus.Internal public static boolean _onUIThread() {
return App._onUIThread();
}

@ApiStatus.Internal public static native long _nMake();
Expand Down
22 changes: 11 additions & 11 deletions macos/java/org/jetbrains/jwm/WindowMac.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,71 +12,71 @@ public WindowMac() {

@Override
public Window setTextInputEnabled(boolean enabled) {
assert _isValidCall();
assert _onUIThread();
// TODO: impl me
return this;
}

@Override
public void show() {
assert _isValidCall();
assert _onUIThread();
_nShow();
}

@Override
public void unmarkText() {
assert _isValidCall();
assert _onUIThread();
// TODO: impl me!
}

@Override
public UIRect getWindowRect() {
assert _isValidCall();
assert _onUIThread();
return _nGetWindowRect();
}

@Override
public UIRect getContentRect() {
assert _isValidCall();
assert _onUIThread();
return _nGetContentRect();
}

@Override
public Window setWindowPosition(int left, int top) {
assert _isValidCall();
assert _onUIThread();
_nSetWindowPosition(left, top);
return this;
}

@Override
public Window setWindowSize(int width, int height) {
assert _isValidCall();
assert _onUIThread();
_nSetWindowSize(width, height);
return this;
}

@Override
public Window setContentSize(int width, int height) {
assert _isValidCall();
assert _onUIThread();
_nSetContentSize(width, height);
return this;
}

@Override
public float getScale() {
assert _isValidCall();
assert _onUIThread();
return _nGetScale();
}

@Override
public void requestFrame() {
assert _isValidCall();
assert _onUIThread();
_nRequestFrame();
}

@Override
public void close() {
assert _isValidCall();
assert _onUIThread();
_nClose();
super.close();
}
Expand Down
16 changes: 7 additions & 9 deletions shared/java/org/jetbrains/jwm/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class App {
public static List<Window> _windows = Collections.synchronizedList(new ArrayList<Window>());
@ApiStatus.Internal
public static long _uiThreadId;
public static boolean _initCalled = false;

/**
* Call this before you do anything else
Expand All @@ -23,15 +22,14 @@ public class App {
public static void init() {
Library.load();
_nInit();
_initCalled = true;
_uiThreadId = Thread.currentThread().getId();
Log.setVerbose("true".equals(System.getenv("JWM_VERBOSE")));
Log.setLogger(System.out::println);
}

@NotNull @SneakyThrows
public static Window makeWindow() {
assert _isValidCall();
assert _onUIThread();
Class cls;
if (Platform.CURRENT == Platform.WINDOWS) {
cls = App.class.forName("org.jetbrains.jwm.WindowWin32");
Expand All @@ -51,17 +49,17 @@ public static Window makeWindow() {
* Will block until you call {@link #terminate()}
*/
public static int start() {
assert _isValidCall();
assert _onUIThread();
return _nStart();
}

public static void terminate() {
assert _isValidCall();
assert _onUIThread();
_nTerminate();
}

public static Screen[] getScreens() {
assert _isValidCall();
assert _onUIThread();
return _nGetScreens();
}

Expand All @@ -74,15 +72,15 @@ public static void runOnUIThread(Runnable callback) {
}

public static Screen getPrimaryScreen() {
assert _isValidCall();
assert _onUIThread();
for (Screen s: getScreens())
if (s.isPrimary())
return s;
throw new IllegalStateException("Can't find primary screen");
}

@ApiStatus.Internal public static boolean _isValidCall() {
return _uiThreadId == Thread.currentThread().getId() && _initCalled;
@ApiStatus.Internal public static boolean _onUIThread() {
return _uiThreadId == Thread.currentThread().getId();
}

@ApiStatus.Internal public static native void _nInit();
Expand Down
14 changes: 7 additions & 7 deletions shared/java/org/jetbrains/jwm/Clipboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Clipboard {
* @param entries List if clipboard entries to set
*/
public static void set(ClipboardEntry ... entries) {
assert _isValidCall();
assert _onUIThread();
assert entries.length > 0;
_nSet(entries);
}
Expand All @@ -41,7 +41,7 @@ public static void set(ClipboardEntry ... entries) {
*/
@Nullable
public static ClipboardEntry get(ClipboardFormat ... formats) {
assert _isValidCall();
assert _onUIThread();
assert formats.length > 0: "must contain at least one format entry";
return _nGet(formats);
}
Expand All @@ -58,12 +58,12 @@ public static ClipboardEntry get(ClipboardFormat ... formats) {
*/
@Nullable
public static ClipboardFormat[] getFormats() {
assert _isValidCall();
assert _onUIThread();
return _nGetFormats();
}

public static void clear() {
assert _isValidCall();
assert _onUIThread();
_nClear();
}

Expand All @@ -72,7 +72,7 @@ public static void clear() {
*/
@NotNull @SneakyThrows
public static ClipboardFormat registerFormat(String formatId) {
assert _isValidCall();
assert _onUIThread();
return _registerFormatInternal(formatId, true);
}

Expand Down Expand Up @@ -103,8 +103,8 @@ public static ClipboardFormat _cacheFormatEntry(String formatId) {
return format;
}

@ApiStatus.Internal public static boolean _isValidCall() {
return App._isValidCall();
@ApiStatus.Internal public static boolean _onUIThread() {
return App._onUIThread();
}

@ApiStatus.Internal public static native void _nSet(ClipboardEntry[] entries);
Expand Down
Loading

0 comments on commit 1505cb3

Please sign in to comment.