Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit abdebb8

Browse files
made additions
1 parent 191dde5 commit abdebb8

File tree

9 files changed

+1931
-77
lines changed

9 files changed

+1931
-77
lines changed

‎README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ How to compile?
66
# Debian based distributions
77
apt install swig
88
```
9-
- Install X11 library. e.g.
9+
- Install GTK library. e.g.
1010
```bash
1111
# Debian based distributions
12-
apt install libx11-dev
12+
apt install libgtk-3-dev
1313
```
1414
- Install PHP development package. e.g.
1515
```bash
@@ -19,10 +19,19 @@ How to compile?
1919
- Execute the following commands
2020
```bash
2121
swig -php Source.i
22-
gcc `php-config --includes` -fpic -c Source_wrap.c Source.c -lX11
23-
gcc --shared Source_wrap.o Source.o -o Source.so
24-
```
25-
- Move the generated file to the ```php-config``` installation directory
26-
```bash
27-
mv Source.so $(php-config --extension-dir)/
28-
```
22+
gcc `php-config --includes` `pkg-config --cflags gtk+-3.0` -fpic -c Source_wrap.c Source.c `pkg-config --libs gtk+-3.0`
23+
gcc `pkg-config --cflags gtk+-3.0` --shared Source_wrap.o Source.o -o <filename>.so `pkg-config --libs gtk+-3.0`
24+
```
25+
- Move the generated file to the ```php-config``` installation directory
26+
```bash
27+
mv <filename>.so $(php-config --extension-dir)/
28+
```
29+
- Copy ```Source.php``` to ```PHP-Desktop/util/ ```
30+
31+
Windows Support
32+
---------------
33+
Well, in theory it should work on windows after
34+
- Installing swig on windows
35+
- Installing windows version of the gtk library
36+
- Compiling this library to a dll. You might have to download php source code and manually add/edit/remove references to libraries. Goodluck trying to get this to work.
37+
- Move the dll to ```<PHP_INSTALLATION_PATH>/ext/

‎Source.c

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,90 @@
1-
#include <X11/Xlib.h>
2-
#include <X11/Xutil.h>
3-
#include<X11/Xos.h>
4-
5-
staticDisplay*display;
6-
staticWindowroot;
7-
staticint screen;
8-
staticGCgc;
9-
10-
WindowcreateWindow(intx, inty, intwidth, intheight, intborder, longborderColor, longrgb) {
11-
Windowwindow=XCreateSimpleWindow(display, root, x, y, width, height, border, (long) borderColor, (long) rgb);
12-
returnwindow;
1+
#include <gtk/gtk.h>
2+
#include <string.h>
3+
4+
5+
GtkWidget*root;
6+
GtkWidget*fixed;
7+
int window_height;
8+
intwindow_width;
9+
charwindow_title[];
10+
11+
voidadd_widget_to_window(GtkWidget*widget, intx, inty) {
12+
gtk_fixed_put(GTK_FIXED(fixed), widget, x, y);
1313
}
1414

15-
Window getParentWindow() {
16-
return root;
15+
void add_button(char label[], int x, int y) {
16+
GtkWidget *button = gtk_button_new_with_label(label);
17+
add_widget_to_window(button, x, y);
1718
}
1819

19-
void changeWindowBackground(Window window, long background) {
20-
XSetWindowBackground(display, window, background);
20+
void add_check_button(char label[], int x, int y) {
21+
GtkWidget *check_btn = gtk_check_button_new_with_label(label);
22+
add_widget_to_window(check_btn, x, y);
2123
}
2224

23-
void changeWindowBorderColor(Window window, long color) {
24-
XSetWindowBorder(display, window, color);
25+
void add_entry(char default_text[], int x, int y) {
26+
GtkWidget *entry = gtk_entry_new();
27+
if(!strcmp(default_text, "")) {
28+
gtk_entry_set_text(GTK_ENTRY(entry), default_text);
29+
}
30+
add_widget_to_window(entry, x, y);
2531
}
2632

27-
void writeText(char[] text, int x, int y, Window window, long background, long foreground) {
28-
gc = XCreateGC(display, window, 0, 0);
29-
XSetBackground(display, gc, (long) background);
30-
XSetForeground(display, gc, (long) foreground);
31-
XDrawString(display, window, gc, x, y, text, strlen(text));
33+
void show_message_dialog(char title[], char message[]) {
34+
// TODO
3235
}
3336

34-
longrgb(intr, intg, intb) {
35-
returnb+ (g<<8) + (r<<16);
37+
voidadd_menu_bar() {
38+
// TODO
3639
}
3740

38-
longred() {
39-
returnrgb(255, 0, 0);
41+
voidadd_radio() {
42+
// TODO
4043
}
4144

42-
long green() {
43-
return rgb(0, 255, 0);
45+
void add_link_button(char link[], char label[], int x, int y) {
46+
GtkWidget *link_btn = gtk_link_button_new_with_label(link, label);
47+
add_widget_to_window(link_btn, x, y);
4448
}
4549

46-
long blue() {
47-
return rgb(0, 0, 255);
50+
void add_switch(int active, int x, int y) {
51+
GtkWidget *switch_btn = gtk_switch_new();
52+
gtk_switch_set_state(GTK_SWITCH(switch_btn), active);
53+
add_widget_to_window(switch_btn, x, y);
4854
}
4955

50-
long white() {
51-
return rgb(255, 255, 255);
56+
void add_label(char text[], int x, int y) {
57+
GtkWidget *label = gtk_label_new(text);
58+
add_widget_to_window(label, x, y);
5259
}
5360

54-
long black() {
55-
return rgb(0, 0, 0);
61+
void add_image(char file[], int x, int y) {
62+
GtkWidget *image = gtk_image_new_from_file(file);
63+
add_widget_to_window(image, x, y);
5664
}
5765

58-
int start(int x, int y, int width, int height, int border, long borderColor, long rgb, char[] windowTitle) {
59-
XEvent xev;
66+
static void activate(GtkApplication *app, gpointer user_data) {
67+
root = gtk_application_window_new(app);
68+
gtk_window_set_title(GTK_WINDOW(root), window_title);
69+
gtk_window_set_default_size(GTK_WINDOW(root), window_width, window_height);
70+
fixed = gtk_fixed_new();
6071

61-
if((display = XOpenDisplay(NULL)) == NULL) {
62-
printf("%s\n", "Couldn't open display");
63-
return 1;
64-
}
72+
g_signal_connect(root, "destroy", G_CALLBACK(gtk_main_quit), NULL);
6573

66-
// Get default screen and root window
67-
screen = DefaultScreen(display);
74+
gtk_container_add(GTK_CONTAINER(root), fixed);
75+
gtk_widget_show_all(root);
76+
}
6877

69-
root=XCreateSimpleWindow(display, RootWindow(display, screen), x, y, width, height, border, (long) borderColor, (long) rgb);
70-
XSetStandardProperties(display, root, windowTitle, "", None, NULL, 0, NULL);
71-
// Map window to display server
72-
XMapWindow(display, root);
78+
intstart(chartitle[], intwidth, intheight) {
79+
window_height=height;
80+
window_width=width;
81+
strcpy(window_title, title);
7382

74-
while(True) {
75-
XNextEvent(display, &xev);
76-
}
83+
GtkApplication *app;
84+
app = gtk_application_new("grephq.phpdesktop", G_APPLICATION_FLAGS_NONE);
85+
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
86+
int status = g_application_run(G_APPLICATION(app), 0, NULL);
87+
g_object_unref(app);
7788

78-
// Unmap window
79-
XUnmapWindow(display, root);
80-
XDestroyWindow(display, root);
81-
// Close connection with display server
82-
XCloseDisplay(display);
83-
return 0;
89+
return status;
8490
}

‎Source.i

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
%module Source
22

3-
extern Window createWindow(int x, int y, int width, int height, int border, long borderColor, long rgb);
4-
extern Window getParentWindow();
5-
extern void changeWindowBackground(Window window, long background);
6-
extern void changeWindowBorderColor(Window window, long color);
7-
extern void writeText(char[] text, int x, int y, Window window, long background, long foreground);
8-
extern long rgb(int r, int g, int b);
9-
extern long red();
10-
extern long green();
11-
extern long blue();
12-
extern long white();
13-
extern long black();
14-
extern int start(int x, int y, int width, int height, int border, long borderColor, long rgb, char[] windowTitle);
3+
extern void add_button(char label[], int x, int y);
4+
extern void add_check_button(char label[], int x, int y);
5+
extern void add_entry(char defaultText[], int x, int y);
6+
extern void show_message_box(char title[], char message[]);
7+
extern void add_menu_bar();
8+
extern void add_radio();
9+
extern void add_link_button(char link[], char label[], int x, int y);
10+
extern void add_switch(int active, int x, int y);
11+
extern void add_label(char text[], int x, int y);
12+
extern void add_image(char file[], int x, int y);
13+
extern int start(char title[], int width, int height);

‎Source.o

6.63 KB
Binary file not shown.

‎Source.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
/* ----------------------------------------------------------------------------
4+
* This file was automatically generated by SWIG (http://www.swig.org).
5+
* Version 4.0.1
6+
*
7+
* This file is not intended to be easily readable and contains a number of
8+
* coding conventions designed to improve portability and efficiency. Do not make
9+
* changes to this file unless you know what you are doing--modify the SWIG
10+
* interface file instead.
11+
* ----------------------------------------------------------------------------- */
12+
13+
// Try to load our extension if it's not already loaded.
14+
if (!extension_loaded('Source')) {
15+
if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
16+
if (!dl('php_Source.dll')) return;
17+
} else {
18+
// PHP_SHLIB_SUFFIX gives 'dylib' on MacOS X but modules are 'so'.
19+
if (PHP_SHLIB_SUFFIX === 'dylib') {
20+
if (!dl('Source.so')) return;
21+
} else {
22+
if (!dl('Source.'.PHP_SHLIB_SUFFIX)) return;
23+
}
24+
}
25+
}
26+
27+
28+
29+
abstract class Source {
30+
static function add_button($label,$x,$y) {
31+
add_button($label,$x,$y);
32+
}
33+
34+
static function add_check_button($label,$x,$y) {
35+
add_check_button($label,$x,$y);
36+
}
37+
38+
static function add_entry($defaultText,$x,$y) {
39+
add_entry($defaultText,$x,$y);
40+
}
41+
42+
static function show_message_box($title,$message) {
43+
show_message_box($title,$message);
44+
}
45+
46+
static function add_menu_bar() {
47+
add_menu_bar();
48+
}
49+
50+
static function add_radio() {
51+
add_radio();
52+
}
53+
54+
static function add_link_button($link,$label,$x,$y) {
55+
add_link_button($link,$label,$x,$y);
56+
}
57+
58+
static function add_switch($active,$x,$y) {
59+
add_switch($active,$x,$y);
60+
}
61+
62+
static function add_label($text,$x,$y) {
63+
add_label($text,$x,$y);
64+
}
65+
66+
static function add_image($file,$x,$y) {
67+
add_image($file,$x,$y);
68+
}
69+
70+
static function start($title,$width,$height) {
71+
return start($title,$width,$height);
72+
}
73+
}
74+
75+
/* PHP Proxy Classes */
76+

‎Source.so

42.8 KB
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /