idle
This commit is contained in:
JianjunLiu 2022-11-24 14:14:16 +08:00
parent af29344e72
commit efe547e628
4 changed files with 103 additions and 94 deletions

View File

@ -215,10 +215,10 @@ type tapplication=class(tcomponent)
**} **}
initialize(); initialize();
{$ifdef linuxgtk} {$ifdef linuxgtk}
idledata :=(new tcbytearray(4))._getptr_(); //idledata :=(new tcbytearray(4))._getptr_();
id := tsl_gtk_idle_interface(idledata);//_wapi.tsl_gtk_idle_interface(idledata); //¹¹Ôìidle //id := tsl_gtk_idle_interface(idledata);//_wapi.tsl_gtk_idle_interface(idledata); //¹¹Ôìidle
_wapi.gtk_main(); _wapi.gtk_main();
_Wapi.g_idle_remove_by_data(idledata); //ɾ³ýidle //_Wapi.g_idle_remove_by_data(idledata); //ɾ³ýidle
return 1; return 1;
{$endif} {$endif}
if not FMessageObj then FMessageObj := new TTagMSG(); if not FMessageObj then FMessageObj := new TTagMSG();

View File

@ -6625,112 +6625,111 @@ function g_main_context_new():pointer;cdecl;external "libgtk-3.so";
function g_main_context_ref(m:pointer):pointer;cdecl;external "libgtk-3.so"; function g_main_context_ref(m:pointer):pointer;cdecl;external "libgtk-3.so";
function g_main_context_acquire(m:pointer):integer;cdecl;external "libgtk-3.so"; function g_main_context_acquire(m:pointer):integer;cdecl;external "libgtk-3.so";
procedure g_main_context_release(m:pointer);cdecl;external "libgtk-3.so"; procedure g_main_context_release(m:pointer);cdecl;external "libgtk-3.so";
type tGtkMessageQueue = class //ÏûÏ¢¶ÓÁÐ type tGtkMessageQueue=class //ÏûÏ¢¶ÓÁÐ
{** {**
@ignore(忽略) @ignore(忽略)
gtk消息队列 gtk消息队列
**} **}
private
public public
function Create(); function Create();
begin begin
Clean(); Clean();
FMainContext := g_main_context_new(); FMainContext := g_main_context_new();
g_main_context_ref(FMainContext); g_main_context_ref(FMainContext);
fLock := 0; fLock := 0;
end end
function Add(h,m,l,w,obj); function Add(h,m,l,w,obj);
begin begin
lock(); lock();
FLen++; FData[FLen]:= array(h,m,l,w,obj);
FData[FLen] := array(h,m,l,w,obj); if FCurrent=FLen then
unlock(); begin
end createidle();
end
function Feach(); FLen++;
begin unlock();
lock(); end
if FCurrent<FLen then function Feach();
begin begin
FCurrent++; lock();
r := FData[FCurrent]; if FCurrent<FLen then
if (FCurrent+1<FLen) and FCurrent>100 then begin
begin r := FData[FCurrent];
FData := FData[FCurrent+1:];//min(FLen-1,FCurrent+100)]; FCurrent++;
FCurrent := -1; if(FCurrent<FLen)and FCurrent>100 then
FLen := length(FData); begin
end FData := FData[FCurrent:]; //min(FLen-1,FCurrent+100)];
end FCurrent :=0;
else FLen := length(FData);
begin end
Clean(); end else
end begin
unlock(); Clean();
return r; end
end unlock();
function cleaneasyLostMessage(h,m); return r;
begin end
idx := FCurrent; function cleaneasyLostMessage(h,m);
lock(); begin
while idx<FLen do idx := FCurrent;
begin lock();
idx++; while idx<FLen do
if FData[idx][0]=h and FData[idx][0]=m then begin
begin if FData[idx][0]=h and FData[idx][0]=m then
FData[idx][0] := 0; begin
end FData[idx][0]:= 0;
end end
unlock(); idx++;
end end
function haseasyLostMessage(h,m); unlock();
begin end
idx := FCurrent; function haseasyLostMessage(h,m);
if idx<FLen then begin
begin idx := FCurrent;
idx++; if idx<FLen then
if ((h=-1) or (FData[idx][0]=h)) and FData[idx][0]=m then begin
begin if((h=-1)or(FData[idx][0]=h))and FData[idx][0]=m then
return 1; begin
end return 1;
end end
end idx++;
private end
function Clean(); end
begin private
function Clean();
FData := array(); begin
FLen := 0; FData := array();
FCurrent := -1; FLen := 0;
FCurrent :=0;
end end
FData; FData;
FCurrent; FCurrent;
FLen; FLen;
FLock ; FLock;
FMainContext; FMainContext;
function lock() function lock()
begin begin
return ; return;
fLock++; fLock++;
if (fLock=1 )then if(fLock=1)then
begin begin
g_main_context_acquire(FMainContext); g_main_context_acquire(FMainContext);
end end
end end
function unlock() function unlock()
begin begin
return ; return;
if (fLock>0) then if(fLock>0)then
begin begin
fLock--; fLock--;
if (fLock=0) then if(fLock=0)then
begin begin
g_main_context_release(FMainContext); g_main_context_release(FMainContext);
end end
end end
end end
end end
function _gtkeventcall_();//消息回调 function _gtkeventcall_();//消息回调
begin begin
r := class(tgtk_ctl_object).DispatchGtkEventCall(params); r := class(tgtk_ctl_object).DispatchGtkEventCall(params);
@ -6839,6 +6838,11 @@ begin
_wapi.cairo_destroy(cr); _wapi.cairo_destroy(cr);
_wapi.gtk_object_set_data(cr); _wapi.gtk_object_set_data(cr);
end end
function createidle();
begin
idledata :=(new tcbytearray(4))._getptr_();
id := tsl_gtk_idle_interface(idledata);
end
function _gtkidledo_(); //回调 function _gtkidledo_(); //回调
begin begin
d := FeachMessageFromGtkMessageQueue(); d := FeachMessageFromGtkMessageQueue();
@ -6873,19 +6877,22 @@ begin
return 1; return 1;
end end
return r; return 1; //r
end end
else else
begin begin
tslprocessmessages(false); tslprocessmessages(false);
//sleep(10); //sleep(10);
end end
r := 1;
end else end else
begin begin
r := 0;
tslprocessmessages(false); tslprocessmessages(false);
//sleep(10);//休息一下 //sleep(10);//休息一下
end end
unit(uvclthreadworker).RunThreadWorkerHost(); unit(uvclthreadworker).RunThreadWorkerHost();
return r;
end end
procedure tslprocessmessages()begin end; procedure tslprocessmessages()begin end;
function InitGtkWindowClass(); //初始化窗口类 function InitGtkWindowClass(); //初始化窗口类

View File

@ -5566,7 +5566,8 @@ type TcustomStatusBar=class(TCustomControl)
if nv<>FItemOder then if nv<>FItemOder then
begin begin
FItemOder := nv; FItemOder := nv;
InvalidateRect(nil,false); if FItems then
InvalidateRect(nil,false);
end end
end end
function paintb();//从左到右 function paintb();//从左到右
@ -6769,6 +6770,7 @@ end
initialization initialization
{$ifdef linux} {$ifdef linux}
class(tUIglobalData).uisetdata("G_T_TTIMER_",class(TCustomTimer)); class(tUIglobalData).uisetdata("G_T_TTIMER_",class(TCustomTimer));
class(TCustomTimer)._wapi.SetTimer(nil,10000,100,getwinprocptr(2));
{$endif} {$endif}
end. end.