All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.bloodshura.ignitium.ntv.sys.impl.UnixNativeSystem Maven / Gradle / Ivy

The newest version!
package com.github.bloodshura.ignitium.ntv.sys.impl;

import com.github.bloodshura.ignitium.ntv.ErrorCodeNativeException;
import com.github.bloodshura.ignitium.ntv.NativeException;
import com.github.bloodshura.ignitium.ntv.lib.Unix;
import com.github.bloodshura.ignitium.ntv.sys.NativeSystem;
import com.sun.jna.platform.unix.X11;
import com.sun.jna.platform.unix.X11.Display;

public class UnixNativeSystem implements NativeSystem {
	@Override
	public void beep() throws NativeException {
		Display display = X11.INSTANCE.XOpenDisplay(null);

		if (display == null) {
			throw new ErrorCodeNativeException("Could not open X11 display");
		}

		int status;

		if ((status = X11.INSTANCE.XBell(display, 100)) != X11.Success) {
			// XBell is fucking returning a BadRequest, EVEN THOUGH IT'S WORKING AND THE PASSED
			// PARAMETERS ARE RIGHT AND ETC. FFS.
			if (status != X11.BadRequest) {
				throw new ErrorCodeNativeException("Could not call X11 bell", status);
			}
		}

		if ((status = X11.INSTANCE.XCloseDisplay(display)) != X11.Success) {
			throw new ErrorCodeNativeException("Could not dispose X11 display", status);
		}
	}

	@Override
	public int getProcessId() throws NativeException {
		return Unix.getpid();
	}

	@Override
	public boolean isProcessPrivileged() throws NativeException {
		return isUserAdmin();
	}

	@Override
	public boolean isUserAdmin() throws NativeException {
		return Unix.getuid() == 0;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy