September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -0,0 +1,138 @@
#include<windows.h>
#include<unistd.h>
#include<stdio.h>
const char g_szClassName[] = "weirdWindow";
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd[3];
MSG Msg;
int i,x=0,y=0;
char str[3][100];
int maxX = GetSystemMetrics(SM_CXSCREEN), maxY = GetSystemMetrics(SM_CYSCREEN);
char messages[15][180] = {"Welcome to the Rosettacode Window C implementation.",
"If you can see two blank windows just behind this message box, you are in luck.",
"Let's get started....",
"Yes, you will be seeing a lot of me :)",
"Now to get started with the tasks, the windows here are stored in an array of type HWND, the array is called hwnd (yes, I know it's very innovative.)",
"Let's compare the windows for equality.",
"Now let's hide Window 1.",
"Now let's see Window 1 again.",
"Let's close Window 2, bye, bye, Number 2 !",
"Let's minimize Window 1.",
"Now let's maximize Window 1.",
"And finally we come to the fun part, watch Window 1 move !",
"Let's double Window 1 in size for all the good work.",
"That's all folks ! (You still have to close that window, that was not part of the contract, sue me :D )"};
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",MB_ICONEXCLAMATION | MB_OK);
return 0;
}
for(i=0;i<2;i++){
sprintf(str[i],"Window Number %d",i+1);
hwnd[i] = CreateWindow(g_szClassName,str[i],WS_OVERLAPPEDWINDOW,i*maxX/2 , 0, maxX/2-10, maxY/2-10,NULL, NULL, hInstance, NULL);
if(hwnd[i] == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd[i], nCmdShow);
UpdateWindow(hwnd[i]);
}
for(i=0;i<6;i++){
MessageBox(NULL, messages[i], "Info",MB_APPLMODAL| MB_ICONINFORMATION | MB_OK);
}
if(hwnd[0]==hwnd[1])
MessageBox(NULL, "Window 1 and 2 are equal.", "Info",MB_APPLMODAL| MB_ICONINFORMATION | MB_OK);
else
MessageBox(NULL, "Nope, they are not.", "Info",MB_APPLMODAL| MB_ICONINFORMATION | MB_OK);
MessageBox(NULL, messages[6], "Info",MB_APPLMODAL| MB_ICONINFORMATION | MB_OK);
ShowWindow(hwnd[0], SW_HIDE);
MessageBox(NULL, messages[7], "Info",MB_APPLMODAL| MB_ICONINFORMATION | MB_OK);
ShowWindow(hwnd[0], SW_SHOW);
MessageBox(NULL, messages[8], "Info",MB_APPLMODAL| MB_ICONINFORMATION | MB_OK);
ShowWindow(hwnd[1], SW_HIDE);
MessageBox(NULL, messages[9], "Info",MB_APPLMODAL| MB_ICONINFORMATION | MB_OK);
ShowWindow(hwnd[0], SW_MINIMIZE);
MessageBox(NULL, messages[10], "Info",MB_APPLMODAL| MB_ICONINFORMATION | MB_OK);
ShowWindow(hwnd[0], SW_MAXIMIZE);
MessageBox(NULL, messages[11], "Info",MB_APPLMODAL| MB_ICONINFORMATION | MB_OK);
ShowWindow(hwnd[0], SW_RESTORE);
while(x!=maxX/2||y!=maxY/2){
if(x<maxX/2)
x++;
if(y<maxY/2)
y++;
MoveWindow(hwnd[0],x,y,maxX/2-10, maxY/2-10,0);
sleep(10);
}
MessageBox(NULL, messages[12], "Info",MB_APPLMODAL| MB_ICONINFORMATION | MB_OK);
MoveWindow(hwnd[0],0,0,maxX, maxY,0);
MessageBox(NULL, messages[13], "Info",MB_APPLMODAL| MB_ICONINFORMATION | MB_OK);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}

View file

@ -0,0 +1,100 @@
package main
import (
"github.com/gotk3/gotk3/gtk"
"log"
"time"
)
func check(err error, msg string) {
if err != nil {
log.Fatal(msg, err)
}
}
func main() {
gtk.Init(nil)
window, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
check(err, "Unable to create window:")
window.SetResizable(true)
window.SetTitle("Window management")
window.SetBorderWidth(5)
window.Connect("destroy", func() {
gtk.MainQuit()
})
stackbox, err := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 10)
check(err, "Unable to create stack box:")
bmax, err := gtk.ButtonNewWithLabel("Maximize")
check(err, "Unable to create maximize button:")
bmax.Connect("clicked", func() {
window.Maximize()
})
bunmax, err := gtk.ButtonNewWithLabel("Unmaximize")
check(err, "Unable to create unmaximize button:")
bunmax.Connect("clicked", func() {
window.Unmaximize()
})
bicon, err := gtk.ButtonNewWithLabel("Iconize")
check(err, "Unable to create iconize button:")
bicon.Connect("clicked", func() {
window.Iconify()
})
bdeicon, err := gtk.ButtonNewWithLabel("Deiconize")
check(err, "Unable to create deiconize button:")
bdeicon.Connect("clicked", func() {
window.Deiconify()
})
bhide, err := gtk.ButtonNewWithLabel("Hide")
check(err, "Unable to create hide button:")
bhide.Connect("clicked", func() {
// not working on Ubuntu 16.04 but window 'dims' after a few seconds
window.Hide()
time.Sleep(10 * time.Second)
window.Show()
})
bshow, err := gtk.ButtonNewWithLabel("Show")
check(err, "Unable to create show button:")
bshow.Connect("clicked", func() {
window.Show()
})
bmove, err := gtk.ButtonNewWithLabel("Move")
check(err, "Unable to create move button:")
isShifted := false
bmove.Connect("clicked", func() {
w, h := window.GetSize()
if isShifted {
window.Move(w-10, h-10)
} else {
window.Move(w+10, h+10)
}
isShifted = !isShifted
})
bquit, err := gtk.ButtonNewWithLabel("Quit")
check(err, "Unable to create quit button:")
bquit.Connect("clicked", func() {
window.Destroy()
})
stackbox.PackStart(bmax, true, true, 0)
stackbox.PackStart(bunmax, true, true, 0)
stackbox.PackStart(bicon, true, true, 0)
stackbox.PackStart(bdeicon, true, true, 0)
stackbox.PackStart(bhide, true, true, 0)
stackbox.PackStart(bshow, true, true, 0)
stackbox.PackStart(bmove, true, true, 0)
stackbox.PackStart(bquit, true, true, 0)
window.Add(stackbox)
window.ShowAll()
gtk.Main()
}

View file

@ -5,11 +5,11 @@ procedure main()
Delay := 3000
W1 := open("Window 1","g","resize=on","size=400,400","pos=100,100","bg=black","fg=red") |
stop("Unbale to open window 1")
stop("Unable to open window 1")
W2 := open("Window 2","g","resize=on","size=400,400","pos=450,450","bg=blue","fg=yellow") |
stop("Unbale to open window 2")
stop("Unable to open window 2")
W3 := open("Window 3","g","resize=on","size=400,400","pos=600,150","bg=orange","fg=black") |
stop("Unbale to open window 3")
stop("Unable to open window 3")
WWrite(W3,"Opened three windows")
WWrite(W3,"Window 1&2 with rectangles")
@ -36,7 +36,7 @@ procedure main()
WAttrib(W2,"size=600,600")
delay(Delay)
WWrite(W3,"Window 2 moveded")
WWrite(W3,"Window 2 moved")
WAttrib(W2,"posx=700","posy=300")
delay(Delay)

View file

@ -16,16 +16,10 @@ import javax.swing.border.EmptyBorder;
public class WindowController extends JFrame {
// Create UI on correct thread
public static void main( final String[] args ) {
EventQueue.invokeLater (
new Runnable() {
public void run() {
new WindowController();
}
}
);
EventQueue.invokeLater( () -> new WindowController() );
}
private JComboBox list;
private JComboBox<ControlledWindow> list;
// Button class to call the right method
private class ControlButton extends JButton {
@ -58,7 +52,7 @@ public class WindowController extends JFrame {
setLayout( new BorderLayout( 3, 3 ) );
getRootPane().setBorder( new EmptyBorder( 3, 3, 3, 3 ) );
add( new JLabel( "Add windows and control them." ), BorderLayout.NORTH );
main.add( list = new JComboBox() );
main.add( list = new JComboBox<>() );
add( main, BorderLayout.CENTER );
controls.setLayout( new GridLayout( 0, 1, 3, 3 ) );
controls.add( new ControlButton( "Add" ) );
@ -103,42 +97,95 @@ public class WindowController extends JFrame {
}
public void doHide() {
( ( JFrame ) list.getSelectedItem() ).setVisible( false );
final JFrame window = getWindow();
if ( null == window ) {
return;
}
window.setVisible( false );
}
public void doShow() {
( ( JFrame ) list.getSelectedItem() ).setVisible( true );
final JFrame window = getWindow();
if ( null == window ) {
return;
}
window.setVisible( true );
}
public void doClose() {
( ( JFrame ) list.getSelectedItem() ).dispose();
final JFrame window = getWindow();
if ( null == window ) {
return;
}
window.dispose();
}
public void doMinimise() {
( ( JFrame ) list.getSelectedItem() ).setState( Frame.ICONIFIED );
final JFrame window = getWindow();
if ( null == window ) {
return;
}
window.setState( Frame.ICONIFIED );
}
public void doMaximise() {
( ( JFrame ) list.getSelectedItem() ).setExtendedState( Frame.MAXIMIZED_BOTH );
final JFrame window = getWindow();
if ( null == window ) {
return;
}
window.setExtendedState( Frame.MAXIMIZED_BOTH );
}
public void doMove() {
( ( JFrame ) list.getSelectedItem() ).setLocation
(
Integer.parseInt( JOptionPane.showInputDialog( "Horizontal position?" ) ),
Integer.parseInt( JOptionPane.showInputDialog( "Vertical position?" ) )
);
final JFrame window = getWindow();
if ( null == window ) {
return;
}
final int hPos = getInt( "Horizontal position?" );
if ( -1 == hPos ) {
return;
}
final int vPos = getInt( "Vertical position?" );
if ( -1 == vPos ) {
return;
}
window.setLocation ( hPos, vPos );
}
public void doResize() {
final JFrame window = ( JFrame ) list.getSelectedItem();
final JFrame window = getWindow();
if ( null == window ) {
return;
}
final int width = getInt( "Width?" );
if ( -1 == width ) {
return;
}
final int height = getInt( "Height?" );
if ( -1 == height ) {
return;
}
window.setBounds ( window.getX(), window.getY(), width, height );
}
window.setBounds
(
window.getX(),
window.getY(),
Integer.parseInt( JOptionPane.showInputDialog( "Width?" ) ),
Integer.parseInt( JOptionPane.showInputDialog( "Height?" ) )
);
private JFrame getWindow() {
final JFrame window = ( JFrame ) list.getSelectedItem();
if ( null == window ) {
JOptionPane.showMessageDialog( this, "Add a window first" );
}
return window;
}
private int getInt(final String prompt) {
final String s = JOptionPane.showInputDialog( prompt );
if ( null == s ) {
return -1;
}
try {
return Integer.parseInt( s );
} catch ( final NumberFormatException x ) {
JOptionPane.showMessageDialog( this, "Not a number" );
return -1;
}
}
}

View file

@ -0,0 +1,43 @@
using Gtk
function controlwindow(win, lab)
sleep(4)
set_gtk_property!(lab, :label, "Hiding...")
sleep(1)
println("Hiding widow")
set_gtk_property!(win, :visible, false)
sleep(5)
set_gtk_property!(lab, :label, "Showing...")
println("Showing window")
set_gtk_property!(win, :visible, true)
sleep(5)
set_gtk_property!(lab, :label, "Resizing...")
println("Resizing window")
resize!(win, 300, 300)
sleep(4)
set_gtk_property!(lab, :label, "Maximizing...")
println("Maximizing window")
sleep(1)
maximize(win)
set_gtk_property!(lab, :label, "Closing...")
sleep(5)
println("Closing window")
destroy(win)
sleep(2)
exit(0)
end
function runwindow()
win = GtkWindow("Window Control Test", 500, 30) |> (GtkFrame() |> (vbox = GtkBox(:v)))
lab = GtkLabel("Window under external control")
push!(vbox, lab)
@async(controlwindow(win, lab))
cond = Condition()
endit(w) = notify(cond)
signal_connect(endit, win, :destroy)
showall(win)
wait(cond)
end
runwindow()

View file

@ -0,0 +1,63 @@
use X11::libxdo;
my $xdo = Xdo.new;
say 'Visible windows:';
printf "Class: %-21s ID#: %10d pid: %5d Name: %s\n", $_<class ID pid name>
for $xdo.get-windows.sort(+*.key)».value;
sleep 2;
my $id = $xdo.get-active-window;
my ($w, $h ) = $xdo.get-window-size( $id );
my ($wx, $wy) = $xdo.get-window-location( $id );
my ($dw, $dh) = $xdo.get-desktop-dimensions( 0 );
$xdo.move-window( $id, 150, 150 );
$xdo.set-window-size( $id, 350, 350, 0 );
sleep .25;
for flat 1 .. $dw - 350, $dw - 350, {$_ - 1} 1 -> $mx { #
my $my = (($mx / $dw * τ).sin * 500).abs.Int;
$xdo.move-window( $id, $mx, $my );
$xdo.activate-window($id);
}
sleep .25;
$xdo.move-window( $id, 150, 150 );
my $dx = $dw - 300;
my $dy = $dh - 300;
$xdo.set-window-size( $id, $dx, $dy, 0 );
sleep .25;
my $s = -1;
loop {
$dx += $s * ($dw / 200).ceiling;
$dy += $s * ($dh / 200).ceiling;
$xdo.set-window-size( $id, $dx, $dy, 0 );
$xdo.activate-window($id);
sleep .005;
$s *= -1 if $dy < 200;
last if $dx >= $dw;
}
sleep .25;
$xdo.set-window-size( $id, $w, $h, 0 );
$xdo.move-window( $id, $wx, $wy );
$xdo.activate-window($id);
sleep .25;
$xdo.minimize($id);
$xdo.activate-window($id);
sleep 1;
$xdo.raise-window($id);
sleep .25;